void IQmolApplication::maybeQuit() { disconnect(this, SIGNAL(lastWindowClosed()), this, SLOT(maybeQuit())); QPixmap pixmap; pixmap.load(":/imageInformation"); QMessageBox messageBox(QMessageBox::NoIcon, "IQmol", "No viewer windows remain"); QPushButton* quitButton = messageBox.addButton("Quit", QMessageBox::AcceptRole); QPushButton* newButton = messageBox.addButton("New", QMessageBox::RejectRole); QPushButton* openButton = messageBox.addButton("Open", QMessageBox::RejectRole); messageBox.setIconPixmap(pixmap); messageBox.exec(); if (messageBox.clickedButton() == quitButton) { QApplication::quit(); }else if (messageBox.clickedButton() == newButton) { MainWindow* mw(new MainWindow()); mw->show(); }else if (messageBox.clickedButton() == openButton) { MainWindow* mw(new MainWindow()); mw->show(); mw->openFile(); } connect(this, SIGNAL(lastWindowClosed()), this, SLOT(maybeQuit())); }
bool IQmolApplication::event(QEvent* event) { bool accepted(false); switch (event->type()) { case QEvent::FileOpen: { QString file(static_cast<QFileOpenEvent*>(event)->file()); queueOpenFiles(QStringList(file)); accepted = true; } break; case QEvent::Close: { disconnect(this, SIGNAL(lastWindowClosed()), this, SLOT(maybeQuit())); accepted = QApplication::event(event); } break; case QEvent::User: { QString file(static_cast<FileOpenEvent*>(event)->file()); open(file); accepted = true; } break; default: accepted = QApplication::event(event); break; } return accepted; }
void IQmolApplication::open(QString const& file) { // This is the first thing that is called once the event loop has started, // even if there is no actual file to open (empty file name). This is an // ideal time to check if OpenBabel is around. initOpenBabel(); MainWindow* mw; QWidget* window(QApplication::activeWindow()); if ( !(mw = qobject_cast<MainWindow*>(window)) ) { mw = new MainWindow(); QApplication::setActiveWindow(mw); } QFileInfo info(file); if (info.exists()) mw->openFile(file); mw->show(); mw->raise(); static bool connected(false); if (!connected) { connect(this, SIGNAL(lastWindowClosed()), this, SLOT(maybeQuit())); connected = true; } QLOG_INFO() << "Number of threads:" << QThread::idealThreadCount(); QLOG_INFO() << "Active threads:" << QThreadPool::globalInstance()->activeThreadCount(); }
void OpenNIC::createActions() { mActionSettings = new QAction(tr("&Settings..."), this); QObject::connect(mActionSettings,SIGNAL(triggered()),this,SLOT(settings())); mActionAbout = new QAction(tr("&About..."), this); QObject::connect(mActionAbout,SIGNAL(triggered()),this,SLOT(about())); mActionQuit = new QAction(tr("&Quit"), this); QObject::connect(mActionQuit,SIGNAL(triggered()),this,SLOT(maybeQuit())); }
KSystemTray::KSystemTray(QWidget *parent, const char *name) : QLabel(parent, name, WType_TopLevel) { #ifdef Q_WS_X11 QXEmbed::initialize(); #endif d = new KSystemTrayPrivate; d->actionCollection = new KActionCollection(this); #ifdef Q_WS_X11 KWin::setSystemTrayWindowFor(winId(), parent ? parent->topLevelWidget()->winId() : qt_xrootwin()); #endif setBackgroundMode(X11ParentRelative); setBackgroundOrigin(WindowOrigin); hasQuit = 0; menu = new KPopupMenu(this); menu->insertTitle(kapp->miniIcon(), kapp->caption()); move(-1000, -1000); KStdAction::quit(this, SLOT(maybeQuit()), d->actionCollection); if(parentWidget()) { new KAction(i18n("Minimize"), KShortcut(), this, SLOT(minimizeRestoreAction()), d->actionCollection, "minimizeRestore"); #ifdef Q_WS_X11 KWin::WindowInfo info = KWin::windowInfo(parentWidget()->winId()); d->on_all_desktops = info.onAllDesktops(); #else d->on_all_desktops = false; #endif } else { d->on_all_desktops = false; } setCaption(KGlobal::instance()->aboutData()->programName()); setAlignment(alignment() | Qt::AlignVCenter | Qt::AlignHCenter); }