rendered paste body#include <QtGui>#include <QDir>#include <QVBoxLayout>#include <QSplashScreen>#include <QScrollArea>//#include "main.h"#include "interfaces.h"#include "mainwindow.h"#include "configdialog.h"#include "filetree.h"#include "project.h"MainWindow::MainWindow(){ QPixmap pixmap = QPixmap(":images/splash.png"); splash = new QSplashScreen(pixmap); splash->show(); createActions(); createMenus(); createToolBars(); createCentralWidget (); readSettings(); loadPlugins (); options = new ConfigDialog (this); /* outputWin = new iOutput (this); buildProj = new iBuild (outputWin->_getWidget()); connect (outputWin, SIGNAL(_closeEvent(QCloseEvent*)), this, SLOT(_closeOutput(QCloseEvent*))); */ _disableActions (); // must make all these title & version // dynamic setWindowTitle (tr("Lyght Code 1.0")); setStatusMsg (tr("Ready")); splash->showMessage (tr("Finished"), Qt::AlignBottom|Qt::AlignLeft); splash->finish (this); delete splash;}void MainWindow::createCentralWidget (){ project = new iProject (this); //connect (project, SIGNAL(_modified()), this, SLOT(_setModified())); connect (project, SIGNAL(_closedOutput()), this, SLOT(_closedOutput())); connect (project, SIGNAL(_closed()), this, SLOT(_disableActions())); connect (project, SIGNAL(_opened()), this, SLOT(_enableActions())); connect (project, SIGNAL(_modified(bool)), this, SLOT(_enableSave(bool))); setCentralWidget (project);}void MainWindow::closeEvent(QCloseEvent *event){ /* loop through all plugins to ensure they * clean up after themselves */ QListIterator <iPlugin *> i(plugins); while (i.hasNext()) { iPlugin *item = i.next (); // if they return false, they're not ready to quit if (!item->_quit ()) { // prompt, force quit? // if (true) event->accept(); // else event->ignore (); event->ignore (); return; } } if (closeProject ()) { writeSettings(); event->accept(); } else { event->ignore(); }}void MainWindow::createActions(){ newProjAct = new QAction (tr("Project"), this); //newProjAct->setShortcut (tr("Ctrl+N")); newProjAct->setStatusTip (tr("Create a new project.")); connect (newProjAct, SIGNAL(triggered()), this, SLOT(newProject())); newFileAct = new QAction (tr("File"), this); newFileAct->setStatusTip (tr("Create a new file.")); connect (newFileAct, SIGNAL(triggered()), this, SLOT(newFile())); openAct = new QAction (tr("Open"), this); openAct->setShortcut(tr("Ctrl+O")); openAct->setStatusTip(tr("Open an existing file")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); closeAct = new QAction (tr("Close"), this); connect (closeAct, SIGNAL(triggered()), this, SLOT(closeProject())); saveAct = new QAction (tr("Save"), this); saveAct->setShortcut(tr("Ctrl+S")); saveAct->setStatusTip(tr("Save the document to disk")); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); saveAsAct = new QAction(tr("Save &As..."), this); saveAsAct->setStatusTip(tr("Save the document under a new name")); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); quitAct = new QAction(tr("Quit"), this); quitAct->setShortcut(tr("Ctrl+Q")); quitAct->setStatusTip(tr("Quits the application")); connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); /**************************************************************************************/ buildAct = new QAction (tr("Build"), this); connect (buildAct, SIGNAL(triggered()), this, SLOT(_build())); rebuildAct = new QAction (tr("Rebuild"), this); connect (rebuildAct, SIGNAL(triggered()), this, SLOT(_rebuild())); cleanAct = new QAction (tr("Clean"), this); connect (cleanAct, SIGNAL(triggered()), this, SLOT(_clean())); outputAct = new QAction (tr("View build output"), this); outputAct->setCheckable (true); connect (outputAct, SIGNAL(triggered(bool)), this, SLOT(_showOutput(bool))); stopAct = new QAction (tr("Stop Build"), this); connect (stopAct, SIGNAL(triggered()), this, SLOT(_stop())); /**************************************************************************************/ configAct = new QAction (tr("Configure"), this); configAct->setStatusTip(tr("Set configuration options")); connect (configAct, SIGNAL(triggered()), this, SLOT(config())); /**************************************************************************************/ aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct->setStatusTip(tr("Information about the QT Library")); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); aboutAct = new QAction (tr("About QTProjman"), this); aboutAct->setStatusTip (tr("Information about QTProjman")); connect (aboutAct, SIGNAL(triggered()), this, SLOT(about())); addAct = new QAction (tr("Add File"), this); connect (addAct, SIGNAL(triggered()), this, SLOT(addFile())); delAct = new QAction (tr("Delete File"), this); connect (delAct, SIGNAL(triggered()), this, SLOT(delFile())); editAct = new QAction (tr("Edit file"), this); //connect (editAct, SIGNAL(triggered()), this, SLOT(editFile())); _setIcons ("default");}void MainWindow::_setIcons (QString themePath){ QString iconPath; if (themePath == "default") iconPath = ":/images"; else { QDir dir (themePath); if (dir.exists()) iconPath = themePath; else iconPath = ":/images"; } newProjAct->setIcon (QIcon(tr("%1/project.png").arg(iconPath))); newFileAct->setIcon (QIcon(tr("%1/filenew.png").arg(iconPath))); openAct->setIcon (QIcon(tr("%1/open.png").arg(iconPath))); closeAct->setIcon (QIcon(tr("%1/close.png").arg(iconPath))); saveAct->setIcon (QIcon(tr("%1/save.png").arg(iconPath))); saveAsAct->setIcon (QIcon(tr("%1/saveas.png").arg(iconPath))); quitAct->setIcon (QIcon(tr("%1/quit.png").arg(iconPath))); buildAct->setIcon (QIcon(tr("%1/build.png").arg(iconPath))); rebuildAct->setIcon (QIcon(tr("%1/rebuild.png").arg(iconPath))); cleanAct->setIcon (QIcon(tr("%1/clean.png").arg(iconPath))); outputAct->setIcon (QIcon(tr("%1/output.png").arg(iconPath))); stopAct->setIcon (QIcon(tr("%1/stop.png").arg(iconPath))); configAct->setIcon (QIcon(tr("%1/configure.png").arg(iconPath))); aboutQtAct->setIcon (QIcon(tr("%1/qt.png").arg(iconPath))); aboutAct->setIcon (QIcon(tr("%1/about.png").arg(iconPath))); addAct->setIcon (QIcon(tr("%1/addfile.png").arg(iconPath))); delAct->setIcon (QIcon(tr("%1/delfile.png").arg(iconPath))); editAct->setIcon (QIcon(tr("%1/edit.png").arg(iconPath)));}void MainWindow::createMenus(){ fileMenu = menuBar()->addMenu(tr("&File")); newMenu = new QMenu("New"); fileMenu->addMenu (newMenu); newMenu->addAction(newProjAct); newMenu->addAction(newFileAct); fileMenu->addAction(openAct); fileMenu->addAction(closeAct); fileMenu->addAction(saveAct); fileMenu->addAction(saveAsAct); fileMenu->addSeparator(); fileMenu->addAction(quitAct); projectMenu = menuBar()->addMenu(tr("&Project")); projectMenu->addAction (buildAct); projectMenu->addAction (rebuildAct); projectMenu->addAction (cleanAct); projectMenu->addAction (outputAct); settingsMenu = menuBar()->addMenu (tr("&Settings")); settingsMenu->addAction (configAct); menuBar()->addSeparator(); helpMenu = menuBar()->addMenu(tr("&Help")); pluginsMenu = new QMenu ("About Plug-In"); helpMenu->addAction (aboutAct); helpMenu->addMenu (pluginsMenu); helpMenu->addAction (aboutQtAct);}void MainWindow::createToolBars(){ fileToolBar = addToolBar(tr("File")); fileToolBar->addAction(saveAct); fileToolBar->addAction(addAct); fileToolBar->addAction(delAct); fileToolBar->addAction(editAct); // maybe a drop-down list of build/rebuild/clean fileToolBar->addAction(buildAct); fileToolBar->addAction(stopAct); fileToolBar->setMovable (FALSE); setIconSize (QSize(32,32));}void MainWindow::newFile (){ if (!project->_newFile ()) if (project->_isOpen()) setStatusMsg (tr("Error adding file.")); else setStatusMsg (tr("Must create/open a project.")); else setStatusMsg (tr("Added file."));}void MainWindow::newProject (){ project->_new ();}void MainWindow::open(){ project->_open ();}void MainWindow::save(){ _enableSave (project->_save());}void MainWindow::saveAs(){ _enableSave (project->_saveAs());}bool MainWindow::closeProject (){ if (project->_close ()) { //setWindowModified (false); //maybe call _reset (); return true; } return false;}void MainWindow::_build (){ project->_build ();}void MainWindow::_rebuild (){ project->_rebuild();}void MainWindow::_clean (){ project->_clean ();}void MainWindow::_stop (){ project->_stop ();}void MainWindow::_showOutput (bool show){ project->_show (show);}void MainWindow::config (){ options->exec ();}void MainWindow::_closedOutput (){ outputAct->setChecked (false);}void MainWindow::_setModified (bool mod){ saveAct->setEnabled (mod); saveAsAct->setEnabled (true);}void MainWindow::_enableActions (){ newFileAct->setEnabled (true); closeAct->setEnabled (true); addAct->setEnabled (true); saveAct->setEnabled (true); delAct->setEnabled (true); editAct->setEnabled (true); buildAct->setEnabled (true); rebuildAct->setEnabled (true); cleanAct->setEnabled (true); stopAct->setEnabled (true);}void MainWindow::_disableActions (){ newFileAct->setEnabled (false); closeAct->setEnabled (false); saveAct->setEnabled (false); saveAsAct->setEnabled (false); addAct->setEnabled (false); delAct->setEnabled (false); editAct->setEnabled (false); buildAct->setEnabled (false); rebuildAct->setEnabled (false); cleanAct->setEnabled (false); stopAct->setEnabled (false);}void MainWindow::_enableSave (bool s){ saveAct->setEnabled (s);}void MainWindow::setStatusMsg (QString msg){ statusBar()->showMessage(msg, 2000);}void MainWindow::readSettings(){ QSettings settings("Ingrato.org", "QTProjman"); settings.beginGroup ("MainWindow"); QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); QSize size = settings.value("size", QSize(400, 400)).toSize(); settings.endGroup (); resize(size); move(pos);}void MainWindow::writeSettings(){ QSettings settings("Ingrato.org", "QTProjman"); settings.beginGroup ("MainWindow"); settings.setValue("pos", pos()); settings.setValue("size", size()); settings.endGroup ();}void MainWindow::setCurrentFile(const QString &fileName){ //fix me QString shownName; if (curFile.isEmpty()) setWindowTitle (shownName); //setWindowTitle (appOptions->getAppName()); else { shownName = strippedName(fileName); setWindowTitle (tr("Lyght Code 1.0")); //setWindowTitle ((tr("%1[*] - ") + tr("Lyght Code 1.0"))).arg(shownName); //setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(appOptions->getAppName())); }}QString MainWindow::strippedName(const QString &fullFileName){ return QFileInfo(fullFileName).fileName();}QList<iPlugin*>* MainWindow::getPlugins (){ return &plugins;}void MainWindow::loadPlugins (){ pluginsDir = QDir (qApp->applicationDirPath());#if defined (Q_OS_WIN) //if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") //pluginsDir.cdUp(); pluginsDir = "plugins";#elif defined (Q_OS_MAC) if (pluginsDir.dirName() == "MacOS") { pluginsDir.cdUp (); pluginsDir.cdUp (); pluginsDir.cdUp (); }#endif pluginsDir.cd ("plugins"); QObject *plugin; foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); if (loader.load()) { plugin = loader.instance(); } else continue; if (plugin) { iPlugin *iplugin = qobject_cast<iPlugin *>(plugin); if (iplugin) { splash->showMessage (tr("Loading Plugin: ") + iplugin->_getName(), Qt::AlignBottom|Qt::AlignLeft); plugins.append (iplugin); iplugin->_init (this); } } }}void MainWindow::about(){ /* DISPLAY: * - icon * - description * - authors * - version */ QDialog *dialog = new QDialog; QLabel *label = new QLabel; label->setPixmap (QPixmap(":images/splash.png")); QPushButton *okButton = new QPushButton (tr("OK")); connect (okButton, SIGNAL(clicked()), dialog, SLOT(close())); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(1); buttonsLayout->addWidget (okButton); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget (label); layout->addLayout (buttonsLayout); layout->setMargin (0); dialog->setLayout (layout); dialog->exec ();}