rendered paste body==main.cpp==
#include <QApplication>
#include <QShortcut>
#include "variables.h"
#include "globalPointers.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
gApp=&app;
QMessageBox about;
about.setWindowTitle("About");
about.setText("MLC Editor 0.1");
MainWindowImpl win;
gWin=&win;
win.newFile();
win.adjust();
win.show();
win.tabWidget->setContextMenuPolicy (Qt::CustomContextMenu);
QShortcut(Qt::CTRL + Qt::Key_W,gWin, SLOT( tabContextMenu() ) );
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
app.connect( win.tabWidget, SIGNAL( currentChanged(int) ), &win, SLOT( adjust() ) );
app.connect( win.actionAbout, SIGNAL( triggered() ), &about, SLOT( exec() ) );
app.connect( win.actionNew, SIGNAL( triggered() ), &win, SLOT( newFile() ) );
app.connect( win.actionOpen, SIGNAL( triggered() ), &win, SLOT( openFile() ) );
app.connect( win.actionSave, SIGNAL( triggered() ), &win, SLOT( saveFile() ) );
app.connect( win.actionSave_As, SIGNAL( triggered() ), &win, SLOT( saveAsFile() ) );
app.connect( win.actionExit, SIGNAL( triggered() ), &win, SLOT( exit() ) );
app.connect( win.tabWidget, SIGNAL( customContextMenuRequested ( QPoint ) ), &win, SLOT( tabContextMenu() ) );
return app.exec();
}
==mainwindowimpl.h==
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
public slots:
void newFile();
void openFile();
void saveFile();
void saveAsFile();
void exit();
void changed(); // When contents of current text box are changed
void adjust(); // Adjust the slots connected to Undo, Redo, etc. actions
void tabContextMenu(); // Executes context menu "Close Tab" etc.
void closeTab();
};
#endif
==mainwindowimpl.cpp==
// THIS IT NOT THE ENTIRE FILE, ONLY THE MOST RELEVANT PART
void MainWindowImpl::tabContextMenu(){
// Put this in main function or something...a new menu doesn't needed to be created and destroyed each time
QMenu menu;
menu.addAction("Close Tab",gWin, SLOT( closeTab() ) );
menu.exec();
}
void MainWindowImpl::closeTab(){
if(tabWidget->count())
tabWidget->removeTab(tabWidget->currentIndex());
}
==globalPointers.h==
#ifndef __GLOBALPOINTERS_H__
#define __GLOBALPOINTERS_H__
#include <QApplication>
#include "mainwindowimpl.h"
#include "ui_mainwindow.h"
extern QApplication* gApp;
extern MainWindowImpl* gWin;
#endif // __GLOBALPOINTERS_H__
==globalpointers.cpp=
#include "globalPointers.h"
QApplication* gApp;
MainWindowImpl* gWin;