From: <si...@us...> - 2010-07-01 09:13:04
|
Revision: 1200 http://qterm.svn.sourceforge.net/qterm/?rev=1200&view=rev Author: sidos Date: 2010-07-01 09:12:56 +0000 (Thu, 01 Jul 2010) Log Message: ----------- this is a major rewrite of frame->subwindow signal passing based on experiments done in branch/frame. it opens possibilities of ansi editor and webbrowser integration. Modified Paths: -------------- trunk/qterm-qt4/src/CMakeLists.txt trunk/qterm-qt4/src/qtermframe.cpp trunk/qterm-qt4/src/qtermglobal.cpp trunk/qterm-qt4/src/qtermscreen.cpp trunk/qterm-qt4/src/qtermwindow.cpp trunk/qterm-qt4/src/ui/mainframe.ui Modified: trunk/qterm-qt4/src/CMakeLists.txt =================================================================== --- trunk/qterm-qt4/src/CMakeLists.txt 2010-06-18 15:00:23 UTC (rev 1199) +++ trunk/qterm-qt4/src/CMakeLists.txt 2010-07-01 09:12:56 UTC (rev 1200) @@ -105,6 +105,7 @@ ui_articledialog.h ui_imageviewer.h ui_keydialog.h + ui_mainframe.h ui_msgdialog.h ui_prefdialog.h ui_quickdialog.h Modified: trunk/qterm-qt4/src/qtermframe.cpp =================================================================== --- trunk/qterm-qt4/src/qtermframe.cpp 2010-06-18 15:00:23 UTC (rev 1199) +++ trunk/qterm-qt4/src/qtermframe.cpp 2010-07-01 09:12:56 UTC (rev 1200) @@ -87,10 +87,12 @@ s_instance = this; setAttribute(Qt::WA_DeleteOnClose); - m_MdiArea = new QMdiArea(this); - m_MdiArea->setViewMode(QMdiArea::TabbedView); + setupUi(this); - setCentralWidget(m_MdiArea); + mdiArea->setViewMode(QMdiArea::TabbedView); + connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), + this, SLOT(windowActivated(QMdiSubWindow*)) ); + setCentralWidget(mdiArea); tray = 0; @@ -109,13 +111,8 @@ initShortcuts(); -//set menubar - initActions(); - - addMainMenu(); - //setup toolbar - addMainTool(); + loadToolbars(); // add the custom defined key updateKeyToolBar(); @@ -125,11 +122,25 @@ loadShortcuts(); -// diaable some menu & toolbar - enableMenuToolBar(false); + initThemeMenu(); + initToolbarMenu(); - initThemesMenu(); + connect(menuWindow, SIGNAL(aboutToShow()), + this, SLOT(windowsMenuAboutToShow())); + connect(actionQuit, SIGNAL(triggered()), + this, SLOT(confirmExitQTerm())); + + connectMenu = new QMenu(this); + QToolButton * connectButton = qobject_cast<QToolButton *> (terminalToolBar->widgetForAction(actionConnect)); + connectButton->setObjectName("buttonConnect"); + + connect(connectMenu, SIGNAL(aboutToShow()), this, SLOT(connectMenuAboutToShow())); + connectButton->setMenu(connectMenu); + connectButton->setPopupMode(QToolButton::InstantPopup); + + groupActions(); + installEventFilter(this); } @@ -138,8 +149,16 @@ { } -//initialize setting from qterm.cfg +QMenu * Frame::createPopupMenu() +{ + QMenu * menuContext = QMainWindow::createPopupMenu(); + menuContext->addAction(actionMenubar); + return menuContext; +} +/********************************************************* + * Initialize and Finalize Routines * + *********************************************************/ void Frame::iniSetting() { Global::instance()->loadConfig(); @@ -147,39 +166,36 @@ restoreGeometry(Global::instance()->loadGeometry()); restoreState(Global::instance()->loadState()); if (Global::instance()->isFullScreen()) { - m_fullAction->setChecked(true); + actionFullscreen->setChecked(true); showFullScreen(); } - mdiTools->setVisible(Global::instance()->showToolBar(mdiTools->objectName())); - mdiconnectTools->setVisible(Global::instance()->showToolBar(mdiconnectTools->objectName())); - key->setVisible(Global::instance()->showToolBar(key->objectName())); - theme = Global::instance()->style(); + QString theme = Global::instance()->style(); QStyle * style = QStyleFactory::create(theme); if (style) qApp->setStyle(style); //language if (Global::instance()->language() == Global::English) - m_engAction->setChecked(true); - else if (Global::instance()->language() == Global::SimpilifiedChinese) - m_chsAction->setChecked(true); + actionEnglish->setChecked(true); + else if (Global::instance()->language() == Global::SimplifiedChinese) + actionSimplified_Chinese->setChecked(true); else if (Global::instance()->language() == Global::TraditionalChinese) - m_chtAction->setChecked(true); + actionTraditional_Chinese->setChecked(true); else - m_engAction->setChecked(true); + actionEnglish->setChecked(true); - m_noescAction->setChecked(true); + actionNone_Color->setChecked(true); switch (Global::instance()->clipConversion()) { case Global::No_Conversion: - m_NoConvAction->setChecked(true); + actionNone->setChecked(true); break; case Global::Simplified_To_Traditional: - m_S2TAction->setChecked(true); + actionCHS_CHT->setChecked(true); break; case Global::Traditional_To_Simplified: - m_T2SAction->setChecked(true); + actionCHT_CHS->setChecked(true); break; default: qDebug("ClipboardConversion: we should not be here"); @@ -187,19 +203,19 @@ } if (Global::instance()->scrollPosition() == Global::Hide) { - m_scrollHideAction->setChecked(true); + actionScroll_Hide->setChecked(true); } else if (Global::instance()->scrollPosition() == Global::Left) { - m_scrollLeftAction->setChecked(true); + actionScroll_Left->setChecked(true); } else { - m_scrollRightAction->setChecked(true); + actionScroll_Right->setChecked(true); } - m_switchAction->setChecked(Global::instance()->showSwitchBar()); - if (Global::instance()->showSwitchBar()) - statusBar()->show(); - else - statusBar()->hide(); + actionStatusbar->setChecked(Global::instance()->showStatusBar()); + statusBar()->setVisible(Global::instance()->showStatusBar()); + + actionMenubar->setChecked(Global::instance()->showMenuBar()); + menuBar()->setVisible(Global::instance()->showMenuBar()); setUseTray(Global::instance()->m_pref.bTray); } @@ -213,8 +229,11 @@ saveToolbars(); } +/********************************************************* + * SLOTS * + *********************************************************/ //addressbook -void Frame::addressBook() +void Frame::on_actionAddressBook_triggered() { addrDialog addr(this, false); @@ -224,7 +243,7 @@ } //quicklogin -void Frame::quickLogin() +void Frame::on_actionQuick_Login_triggered() { quickDialog quick(this); @@ -235,10 +254,11 @@ } } +//quit bool Frame::confirmExitQTerm() { QList<QVariant> sites; - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); + QList<QMdiSubWindow *> windows = mdiArea->subWindowList(); QStringList titleList; for (int i = 0; i < int(windows.count()); ++i) { if ((qobject_cast<Window *>(windows.at(i)))->isConnected()) { @@ -260,11 +280,10 @@ // We should never reach here; return true; } - void Frame::saveAndDisconnect() { QList<QVariant> sites; - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); + QList<QMdiSubWindow *> windows = mdiArea->subWindowList(); QStringList titleList; for (int i = 0; i < int(windows.count()); ++i) { if ((qobject_cast<Window *>(windows.at(i)))->isConnected()) { @@ -286,29 +305,32 @@ //create a new display window void Frame::newWindow(const Param& param, int index) { - Window * window = new Window(this, param, index, m_MdiArea, - 0); - QMdiSubWindow * w = m_MdiArea->addSubWindow(window); - window->setWindowTitle(param.m_strName); + Window * window = new Window(this, param, index, mdiArea, 0); + window->setWindowTitle(param.m_strName); window->setWindowIcon(QIcon(":/pic/tabpad.png")); window->setAttribute(Qt::WA_DeleteOnClose); - if (m_menuBarAction->isChecked()) { - w->setWindowFlags(Qt::FramelessWindowHint); - } window->showMaximized(); - m_MdiArea->setActiveSubWindow(window); + mdiArea->addSubWindow(window); + mdiArea->setActiveSubWindow(window); + connect(window, SIGNAL(destroyed(QObject*)), + this, SLOT(windowClosed(QObject*))); } //slot Help->About QTerm -void Frame::aboutQTerm() +void Frame::on_actionAbout_QTerm_triggered() { aboutDialog about(this); - about.exec(); } +//slot Help->About Qt +void Frame::on_actionAbout_Qt_triggered() +{ + qApp->aboutQt(); +} + //slot Help->Homepage -void Frame::homepage() +void Frame::on_actionQTerm_Online_triggered() { QString strUrl = "http://www.qterm.org"; Global::instance()->openUrl(strUrl); @@ -317,14 +339,14 @@ //slot Windows menu aboutToShow void Frame::windowsMenuAboutToShow() { - windowsMenu->clear(); - QAction * cascadeAction = windowsMenu->addAction(tr("&Cascade"), m_MdiArea, SLOT(cascadeSubWindows())); - QAction * tileAction = windowsMenu->addAction(tr("&Tile"), m_MdiArea, SLOT(tileSubWindows())); - if (m_MdiArea->subWindowList().isEmpty()) { + menuWindow->clear(); + QAction * cascadeAction = menuWindow->addAction(tr("&Cascade"), mdiArea, SLOT(cascadeSubWindows())); + QAction * tileAction = menuWindow->addAction(tr("&Tile"), mdiArea, SLOT(tileSubWindows())); + if (mdiArea->subWindowList().isEmpty()) { cascadeAction->setEnabled(false); tileAction->setEnabled(false); } - windowsMenu->addSeparator(); + menuWindow->addSeparator(); #ifdef Q_OS_MACX // used to dock the programe @@ -332,16 +354,16 @@ windowsMenu->addAction(tr("&Main Window"), this, SLOT(trayShow())); #endif - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); + QList<QMdiSubWindow *> windows = mdiArea->subWindowList(); QActionGroup * windowsGroup = new QActionGroup(this); windowsGroup->setExclusive(true); for (int i = 0; i < int(windows.count()); ++i) { - QAction * idAction = windowsMenu->addAction(windows.at(i)->windowTitle(), + QAction * idAction = menuWindow->addAction(windows.at(i)->windowTitle(), this, SLOT(windowsMenuActivated())); idAction->setCheckable(true); idAction->setData(i); windowsGroup->addAction(idAction); - idAction->setChecked(m_MdiArea->activeSubWindow() == windows.at(i)); + idAction->setChecked(mdiArea->activeSubWindow() == windows.at(i)); } } @@ -354,7 +376,7 @@ return; } int id = qobject_cast<QAction *>(action)->data().toInt(); - Window * w = qobject_cast<Window *>(m_MdiArea->subWindowList().at(id)); + Window * w = qobject_cast<Window *>(mdiArea->subWindowList().at(id)); if (w) { w->setFocus(); w->showMaximized(); @@ -363,7 +385,7 @@ } } -void Frame::popupConnectMenu() +void Frame::connectMenuAboutToShow() { connectMenu->clear(); @@ -390,38 +412,97 @@ newWindow(param, id); } +/********************************************************* + * Window Switch Management * + *********************************************************/ +void Frame::windowClosed(QObject*w) +{ + QList<QMdiSubWindow *> listWindow = mdiArea->subWindowList(); + // if no window left, only show basic actions + if(listWindow.count()==0) { + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + foreach(QAction* action, actions) + action->setVisible(listBasicActions.contains(action->objectName()) + || action->actionGroup()!=actionsExtra); + } +} + +void Frame::windowActivated(QMdiSubWindow * w) +{ + WindowBase * wb=qobject_cast<WindowBase*>(w); + if(wb==0) + return; + + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + foreach(QAction* action, actions) + { + // only show actions belonging to BasicActions or WindowActions + action->setVisible(listBasicActions.contains(action->objectName()) + || action->actionGroup()!=actionsExtra + || wb->hasAction(action->objectName())); + // update checkable actions status + if (wb->hasAction(action->objectName()) && action->isCheckable()) + action->setChecked(wb->isActionChecked(action->objectName())); + } +} + +void Frame :: actionsDispatcher(QAction* action) +{ + WindowBase * wb=qobject_cast<WindowBase*>(mdiArea->activeSubWindow()); + if(wb==0) + return; + if (action->isCheckable()) + { + QString nameSlot="on_"+action->objectName()+"_toggled"; + if(wb->hasAction(action->objectName())) + { + bool ret=QMetaObject::invokeMethod(wb, + nameSlot.toLatin1().constData(), Q_ARG(bool, action->isChecked())); + if(!ret) + qWarning("Failed to execute %s", + nameSlot.toLatin1().constData()); + } + } + else + { + QString nameSlot="on_"+action->objectName()+"_triggered"; + if(wb->hasAction(action->objectName())) + { + bool ret=QMetaObject::invokeMethod(wb, + nameSlot.toLatin1().constData()); + if(!ret) + qWarning("Failed to execute %s", + nameSlot.toLatin1().constData()); + } + + } +} + void Frame::switchWin(int id) { - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); + QList<QMdiSubWindow *> windows = mdiArea->subWindowList(); if (windows.count() <= id && id < 200) return; if (id == 200) { - m_MdiArea->activatePreviousSubWindow(); + mdiArea->activatePreviousSubWindow(); return; } if (id == 201 || id == 202) { - m_MdiArea->activateNextSubWindow(); + mdiArea->activateNextSubWindow(); return; } QMdiSubWindow *w = windows.at(id); if (w != NULL) { - m_MdiArea->setActiveSubWindow(w); + mdiArea->setActiveSubWindow(w); } } -//slot draw something e.g. logo in the background -//TODO : draw a pixmap in the background -void Frame::paintEvent(QPaintEvent *) -{ - -} - void Frame::closeEvent(QCloseEvent * clse) { - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); + QList<QMdiSubWindow *> windows = mdiArea->subWindowList(); for (int i = 0; i < int(windows.count()); ++i) { if (((Window *)windows.at(i))->isConnected()) { @@ -441,70 +522,34 @@ void Frame::updateLang(QAction * action) { - QMessageBox::information(this, "QTerm", - tr("This will take effect after restart,\nplease close all windows and restart.")); - Config * conf = Global::instance()->fileCfg(); - conf->setItemValue("global", "language", action->data().toString()); - conf->save(); + if (action == actionEnglish) + Global::instance()->setLanguage(Global::English); + else if (action == actionSimplified_Chinese) + Global::instance()->setLanguage(Global::SimplifiedChinese); + else if (action == actionTraditional_Chinese) + Global::instance()->setLanguage(Global::TraditionalChinese); } void Frame::connectIt() { - if (m_MdiArea->activeSubWindow() == NULL) { + if (mdiArea->activeSubWindow() == NULL) { Param param; Global::instance()->loadAddress(-1, param); newWindow(param); } else - if (!qobject_cast<Window *>(m_MdiArea->activeSubWindow())->isConnected()) - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->reconnect(); + if (!qobject_cast<Window *>(mdiArea->activeSubWindow())->isConnected()) + qobject_cast<Window *>(mdiArea->activeSubWindow())->reconnect(); } -void Frame::disconnect() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->disconnect(); -} -void Frame::copy() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->copy(); -} -void Frame::paste() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->paste(); -} -void Frame::copyRect(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bCopyRect = isEnabled; -} - -void Frame::copyColor(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bCopyColor = isEnabled; -} - -void Frame::copyArticle() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->copyArticle(); -} - -void Frame::autoCopy(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bAutoCopy = isEnabled; -} - -void Frame::wordWrap(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bWordWrap = isEnabled; -} - void Frame::updateESC(QAction * action) { - if (action->objectName() == "actionNoESC") { + if (action == actionNone_Color) { Global::instance()->setEscapeString(""); - } else if (action->objectName() == "actionESCESC") { + } else if (action == actionESC_ESC) { Global::instance()->setEscapeString("^[^[["); - } else if (action->objectName() == "actionUESC") { + } else if (action == actionCtrl_U) { Global::instance()->setEscapeString("^u["); - } else if (action->objectName() == "actionCustomESC") { + } else if (action == actionCustom) { bool ok; QString strEsc = QInputDialog::getText(this, "define escape", "scape string *[", QLineEdit::Normal, Global::instance()->escapeString(), &ok); if (ok) @@ -516,23 +561,19 @@ void Frame::updateCodec(QAction * action) { - if (action->objectName() == "actionNoConversion") { + if (action == actionNone) { Global::instance()->setClipConversion(Global::No_Conversion); - } else if (action->objectName() == "actionS2T") { + } else if (action == actionCHS_CHT) { Global::instance()->setClipConversion(Global::Simplified_To_Traditional); - } else if (action->objectName() == "actionT2S") { + } else if (action == actionCHT_CHS) { Global::instance()->setClipConversion(Global::Traditional_To_Simplified); } else { qDebug("updateCodec: should not be here"); } } -void Frame::refresh() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->refresh(); -} -void Frame::uiFont() +void Frame::on_actionFont_triggered() { bool ok; QFont font = QFontDialog::getFont(&ok, qApp->font()); @@ -545,25 +586,13 @@ } } -void Frame::hideMenuBar(bool hide) +void Frame::on_actionMenubar_toggled(bool show) { - if (hide) { - menuBar()->hide(); - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); - foreach (QMdiSubWindow * window, windows) { - window->setWindowFlags(Qt::FramelessWindowHint); - } - } - else { - QList<QMdiSubWindow *> windows = m_MdiArea->subWindowList(); - foreach (QMdiSubWindow * window, windows) { - window->setWindowFlags(Qt::SubWindow); - } - menuBar()->show(); - } + Global::instance()->setMenuBar(show); + menuBar()->setVisible(show); } -void Frame::triggerFullScreen(bool isFullScreen) +void Frame::on_actionFullscreen_triggered(bool isFullScreen) { Global::instance()->setFullScreen(isFullScreen); @@ -571,50 +600,50 @@ if (isFullScreen) { Global::instance()->saveGeometry(saveGeometry()); Global::instance()->saveState(saveState()); - //menuBar()->hide(); - mdiTools->hide(); - mdiconnectTools->hide(); - key->hide(); - //showStatusBar(); - //showSwitchBar(); + mainToolBar->hide(); + terminalToolBar->hide(); + keyToolBar->hide(); showFullScreen(); } else { - //menuBar()->show(); restoreGeometry(Global::instance()->loadGeometry()); restoreState(Global::instance()->loadState()); emit scrollChanged(); showNormal(); - //showStatusBar(); - //showSwitchBar(); } - m_fullAction->setChecked(isFullScreen); + actionFullscreen->setChecked(isFullScreen); } -void Frame::bosscolor() +void Frame::initToolbarMenu() { - bool tmp = !Global::instance()->isBossColor(); - Global::instance()->setBossColor(tmp); - - emit bossColor(); - - m_bossAction->setChecked(tmp); + menuToolbar->clear(); + foreach(QToolBar *toolbar, findChildren<QToolBar *>()) + menuToolbar->addAction(toolbar->toggleViewAction()); } -void Frame::initThemesMenu() +void Frame::initThemeMenu() { - themesMenu->clear(); + menuTheme->clear(); QActionGroup * themesGroup = new QActionGroup(this); QStringList styles = QStyleFactory::keys(); for (QStringList::ConstIterator it = styles.begin(); it != styles.end(); it++) themesGroup->addAction(insertThemeItem(*it)); - connect(themesGroup, SIGNAL(triggered(QAction*)), this, SLOT(themesMenuActivated(QAction*))); + connect(themesGroup, SIGNAL(triggered(QAction*)), + this, SLOT(themesMenuActivated(QAction*))); } - +QAction * Frame::insertThemeItem(const QString & themeitem) +{ + QAction * idAction = new QAction(themeitem, this); + menuTheme->addAction(idAction); + idAction->setCheckable(true); + idAction->setChecked( + themeitem.compare(qApp->style()->objectName(), Qt::CaseInsensitive)==0); + return idAction; +} void Frame::themesMenuActivated(QAction * action) { - theme = action->text(); + QString theme = action->text(); QStyle * style = QStyleFactory::create(theme); if (style) { qApp->setStyle(style); @@ -624,11 +653,11 @@ void Frame::updateScroll(QAction * action) { - if (action->objectName() == "actionHide") { + if (action == actionScroll_Hide) { Global::instance()->setScrollPosition(Global::Hide); - } else if (action->objectName() == "actionLeft") { + } else if (action == actionScroll_Left) { Global::instance()->setScrollPosition(Global::Left); - } else if (action->objectName() == "actionRight") { + } else if (action == actionScroll_Right) { Global::instance()->setScrollPosition(Global::Right); } else { qDebug("updateScroll: should not be here"); @@ -636,29 +665,15 @@ emit scrollChanged(); } -void Frame::updateSwitchBar(bool isEnabled) +void Frame::on_actionStatusbar_toggled(bool isEnabled) { - Global::instance()->setSwitchBar(isEnabled); - - if (Global::instance()->showSwitchBar()) - statusBar()->show(); - else - statusBar()->hide(); -} - -void Frame::updateStatusBar(bool isEnabled) -{ Global::instance()->setStatusBar(isEnabled); - + statusBar()->setVisible(isEnabled); emit statusBarChanged(isEnabled); } -void Frame::setting() +void Frame::on_actionDefault_Session_Setting_triggered() { - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->setting(); -} -void Frame::defaultSetting() -{ addrDialog set(this, true); if (Global::instance()->addrCfg()->hasSection("default")) @@ -672,7 +687,7 @@ } } -void Frame::preference() +void Frame::on_actionPreference_triggered() { prefDialog pref(this); @@ -682,7 +697,7 @@ } } -void Frame::keySetup() +void Frame::on_actionKey_Setup_triggered() { keyDialog keyDlg(this); if (keyDlg.exec() == 1) { @@ -690,7 +705,7 @@ } } -void Frame::printScreen() +void Frame::on_actionPrint_triggered() { QPrinter printer(QPrinter::HighResolution); QPrintDialog *dialog = new QPrintDialog(&printer, this); @@ -699,78 +714,21 @@ return; QPainter painter; painter.begin(&printer); - QPixmap screen = QPixmap::grabWidget(qobject_cast<Window *>(m_MdiArea->activeSubWindow())); + QPixmap screen = QPixmap::grabWidget(qobject_cast<Window *>(mdiArea->activeSubWindow())); QPixmap target = screen.scaled(printer.pageRect().width(),printer.pageRect().height(),Qt::KeepAspectRatio,Qt::SmoothTransformation); painter.drawPixmap(0,0,target); painter.end(); } - -void Frame::antiIdle(bool isEnabled) +void Frame::on_actionImage_Viewer_triggered() { - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->antiIdle(isEnabled); -} - -void Frame::autoReply(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->autoReply(isEnabled); -} - -void Frame::viewMessages() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->viewMessages(); -} - -void Frame::updateMouse(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bMouse = isEnabled; - m_mouseAction->setChecked(qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bMouse); -} - -void Frame::viewImages() -{ Image *pViewer = new Image(Global::instance()->m_pref.strPoolPath); pViewer->show(); } -void Frame::updateBeep(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bBeep = isEnabled; - m_beepAction->setChecked(qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bBeep); -} - -void Frame::reconnect(bool isEnabled) -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->m_bReconnect = isEnabled; -} - -void Frame::debugConsole() -{ -#ifndef SCRIPTTOOLS_ENABLED - QMessageBox::information(this, "QTerm", - tr("You need to enable the script engine debugger to use this feature. Please recompile QTerm with the debugger enabled (need Qt 4.5 or newer version)")); -#else - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->debugConsole(); -#endif -} - -void Frame::reloadScript() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->initScript(); -} - -void Frame::runScript() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->runScript(); -} -void Frame::stopScript() -{ - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->stopScript(); -} - void Frame::keyClicked(int id) { - if (qobject_cast<Window *>(m_MdiArea->activeSubWindow()) == NULL) + if (qobject_cast<Window *>(mdiArea->activeSubWindow()) == NULL) return; Config * conf = Global::instance()->fileCfg(); @@ -780,42 +738,14 @@ QString strTmp = conf->getItemValue("key", strItem).toString(); if (strTmp[0] == '0') { // key - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->externInput(strTmp.mid(1)); + qobject_cast<Window *>(mdiArea->activeSubWindow())->externInput(strTmp.mid(1)); } else if (strTmp[0] == '1') { // script - qobject_cast<Window *>(m_MdiArea->activeSubWindow())->runScript(strTmp.mid(1)); + qobject_cast<Window *>(mdiArea->activeSubWindow())->runScript(strTmp.mid(1)); } else if (strTmp[0] == '2') { // program system((strTmp.mid(1) + " &").toLocal8Bit()); } } -void Frame::addMainTool() -{ - mdiTools = addToolBar("Main ToolBar"); - mdiTools->setObjectName("mainToolBar"); - - QAction * connectAction = new QAction(QIcon(":/pic/connect.png"), tr("&Connect"), this); - connectAction->setObjectName("actionConnectButton"); - mdiTools->addAction(connectAction); - connectMenu = new QMenu(this); - - QToolButton * connectButton = qobject_cast<QToolButton *> (mdiTools->widgetForAction(connectAction)); - connectButton->setObjectName("buttonConnect"); - - connect(connectMenu, SIGNAL(aboutToShow()), this, SLOT(popupConnectMenu())); - connectButton->setMenu(connectMenu); - connectButton->setPopupMode(QToolButton::InstantPopup); - - // custom define - key = addToolBar("Custom Key"); - key->setObjectName("customKeyToolBar"); - - // the toolbar - mdiconnectTools = addToolBar("BBS Operations"); - mdiconnectTools->setObjectName("bbsOperationsToolBar"); - - loadToolbars(); -} - void Frame::initShortcuts() { int i = 0; @@ -853,438 +783,24 @@ connect(windowMapper, SIGNAL(mapped(int)), this, SLOT(switchWin(int))); } -void Frame::initActions() -{ - m_connectAction = new QAction(QIcon(":/pic/connect.png"), tr("&Connect"), this); - m_connectAction->setObjectName("actionConnect"); - m_disconnectAction = new QAction(QIcon(":/pic/disconnect.png"), tr("&Disconnect"), this); - m_disconnectAction->setObjectName("actionDisconnect"); - m_addressAction = new QAction(QIcon(":/pic/addr.png"), tr("&Address Book..."), this); - m_addressAction->setObjectName("actionAddress"); - m_quickConnectAction = new QAction(QIcon(":/pic/quick.png"), tr("&Quick Login..."), this); - m_quickConnectAction->setObjectName("actionQuickConnect"); - m_printAction = new QAction(tr("&Print..."), this); - m_printAction->setObjectName("actionPrint"); - m_exitAction = new QAction(tr("&Exit"), this); - m_exitAction->setObjectName("actionExit"); - - m_copyAction = new QAction(QIcon(":/pic/copy.png"), tr("&Copy"), this); - m_copyAction->setObjectName("actionCopy"); - m_pasteAction = new QAction(QIcon(":/pic/paste.png"), tr("&Paste"), this); - m_pasteAction->setObjectName("actionPaste"); - m_colorCopyAction = new QAction(QIcon(":/pic/color-copy.png"), tr("C&opy With Color"), this); - m_colorCopyAction->setObjectName("actionColorCopy"); - m_colorCopyAction->setCheckable(true); - m_rectAction = new QAction(QIcon(":/pic/rect.png"), tr("&Rectangle Select"), this); - m_rectAction->setObjectName("actionRect"); - m_rectAction->setCheckable(true); - m_autoCopyAction = new QAction(tr("Auto Copy &Select"), this); - m_autoCopyAction->setObjectName("actionAutoCopy"); - m_autoCopyAction->setCheckable(true); - m_wwrapAction = new QAction(tr("P&aste With Wordwrap"), this); - m_wwrapAction->setObjectName("actionWordWrap"); - m_wwrapAction->setCheckable(true); - - QActionGroup * escapeGroup = new QActionGroup(this); - m_noescAction = new QAction(tr("&None"), this); - m_noescAction->setObjectName("actionNoESC"); - m_noescAction->setCheckable(true); - m_escescAction = new QAction(tr("&ESC ESC ["), this); - m_escescAction->setObjectName("actionESCESC"); - m_escescAction->setCheckable(true); - m_uescAction = new QAction(tr("Ctrl+&U ["), this); - m_uescAction->setObjectName("actionUESC"); - m_uescAction->setCheckable(true); - m_customescAction = new QAction(tr("&Custom..."), this); - m_customescAction->setObjectName("actionCustomESC"); - m_customescAction->setCheckable(true); - escapeGroup->addAction(m_noescAction); - escapeGroup->addAction(m_escescAction); - escapeGroup->addAction(m_uescAction); - escapeGroup->addAction(m_customescAction); - - QActionGroup * codecGroup = new QActionGroup(this); - m_NoConvAction = new QAction(tr("&No Conversion"), this); - m_NoConvAction->setObjectName("actionNoConversion"); - m_NoConvAction->setCheckable(true); - m_S2TAction = new QAction(tr("&Simplified to Traditional"), this); - m_S2TAction->setObjectName("actionS2T"); - m_S2TAction->setCheckable(true); - m_T2SAction = new QAction(tr("&Traditional to Simplified"), this); - m_T2SAction->setObjectName("actionBig5"); - m_T2SAction->setCheckable(true); - codecGroup->addAction(m_NoConvAction); - codecGroup->addAction(m_S2TAction); - codecGroup->addAction(m_T2SAction); - - m_refreshAction = new QAction(QIcon(":/pic/refresh.png"), tr("&Refresh"), this); - m_refreshAction->setObjectName("actionRefresh"); - - QActionGroup * langGroup = new QActionGroup(this); - m_engAction = new QAction(tr("&English"), this); - m_engAction->setObjectName("actionEng"); - m_engAction->setCheckable(true); - m_engAction->setData("eng"); - m_chsAction = new QAction(tr("&Simplified Chinese"), this); - m_chsAction->setObjectName("actionChs"); - m_chsAction->setCheckable(true); - m_chsAction->setData("chs"); - m_chtAction = new QAction(tr("&Traditional Chinese"), this); - m_chtAction->setObjectName("actionCht"); - m_chtAction->setCheckable(true); - m_chtAction->setData("cht"); - langGroup->addAction(m_engAction); - langGroup->addAction(m_chsAction); - langGroup->addAction(m_chtAction); - - m_uiFontAction = new QAction(tr("&UI Font..."), this); - m_uiFontAction->setObjectName("actionUiFont"); - m_fullAction = new QAction(tr("&Full Screen"), this); - m_fullAction->setObjectName("actionFull"); - m_fullAction->setCheckable(true); - addAction(m_fullAction); - m_menuBarAction= new QAction(tr("&Hide Menu Bar"), this); - m_menuBarAction->setObjectName("actionMenuBar"); - m_menuBarAction->setCheckable(true); - addAction(m_menuBarAction); - m_bossAction = new QAction(tr("Boss &Color"), this); - m_bossAction->setObjectName("actionBoss"); - - QActionGroup * scrollGroup = new QActionGroup(this); - m_scrollHideAction = new QAction(tr("&Hide"), this); - m_scrollHideAction->setObjectName("actionHide"); - m_scrollHideAction->setCheckable(true); - m_scrollLeftAction = new QAction(tr("&Left"), this); - m_scrollLeftAction->setObjectName("actionLeft"); - m_scrollLeftAction->setCheckable(true); - m_scrollRightAction = new QAction(tr("&Right"), this); - m_scrollRightAction->setObjectName("actionRight"); - m_scrollRightAction->setCheckable(true); - scrollGroup->addAction(m_scrollHideAction); - scrollGroup->addAction(m_scrollLeftAction); - scrollGroup->addAction(m_scrollRightAction); - - m_switchAction = new QAction(tr("S&witch Bar"), this); - m_switchAction->setObjectName("actionSwitch"); - m_switchAction->setCheckable(true); - - m_currentSessionAction = new QAction(QIcon(":/pic/pref.png"), tr("&Setting For Currrent Session..."), this); - m_currentSessionAction->setObjectName("actionCurrentSession"); - m_defaultAction = new QAction(tr("&Default Setting..."), this); - m_defaultAction->setObjectName("actionDefault"); - m_prefAction = new QAction(tr("&Preference..."), this); - m_prefAction->setObjectName("actionPref"); - - m_copyArticleAction = new QAction(QIcon(":/pic/article.png"), tr("&Copy Article..."), this); - m_copyArticleAction->setObjectName("actionCopyArticle"); - m_antiIdleAction = new QAction(QIcon(":/pic/anti-idle.png"), tr("Anti &Idle"), this); - m_antiIdleAction->setObjectName("actionAntiIdle"); - m_antiIdleAction->setCheckable(true); - m_autoReplyAction = new QAction(QIcon(":/pic/auto-reply.png"), tr("Auto &Reply"), this); - m_autoReplyAction->setObjectName("actionAutoReply"); - m_autoReplyAction->setCheckable(true); - m_viewMessageAction = new QAction(QIcon(":/pic/message.png"), tr("&View Messages..."), this); - m_viewMessageAction->setObjectName("actionViewMessage"); - m_beepAction = new QAction(QIcon(":/pic/sound.png"), tr("&Beep "), this); - m_beepAction->setObjectName("actionBeep"); - m_beepAction->setCheckable(true); - m_mouseAction = new QAction(QIcon(":/pic/mouse.png"), tr("&Mouse Support"), this); - m_mouseAction->setObjectName("actionMouse"); - m_mouseAction->setCheckable(true); - m_viewImageAction = new QAction(tr("&Image Viewer..."), this); - m_viewImageAction->setObjectName("actionViewImage"); - - m_scriptReloadAction = new QAction(tr("&Reload System Script"), this); - m_scriptReloadAction->setObjectName("actionScriptReload"); - m_scriptReloadAction->setEnabled(false); - m_scriptRunAction = new QAction(tr("&Run..."), this); - m_scriptRunAction->setObjectName("actionScriptRun"); - m_scriptRunAction->setEnabled(false); - m_scriptStopAction = new QAction(tr("&Stop"), this); - m_scriptStopAction->setObjectName("actionScriptStop"); - m_scriptStopAction->setEnabled(false); - m_scriptDebugAction = new QAction(tr("&Debug..."), this); - m_scriptDebugAction->setObjectName("actionScriptDebug"); - m_scriptDebugAction->setEnabled(false); - - m_aboutAction = new QAction(tr("About &QTerm"), this); - m_aboutAction->setObjectName("actionAbout"); - m_homepageAction = new QAction(tr("QTerm's &Homepage"), this); - m_homepageAction->setObjectName("actionHomepage"); - - m_reconnectAction = new QAction(QIcon(":/pic/reconnect.png"), tr("Auto Reconnect"), this); - m_reconnectAction->setObjectName("actionReconnect"); - m_reconnectAction->setCheckable(true); - - m_shortcutsAction = new QAction(tr("&Configure Shortcuts..."),this); - m_shortcutsAction->setObjectName("actionShortcuts"); - - m_toolbarsAction = new QAction(tr("Configure &Toolbars..."),this); - m_toolbarsAction->setObjectName("actionToolbars"); - - connect(m_connectAction, SIGNAL(triggered()), this, SLOT(connectIt())); - connect(m_disconnectAction, SIGNAL(triggered()), this, SLOT(disconnect())); - connect(m_addressAction, SIGNAL(triggered()), this, SLOT(addressBook())); - connect(m_quickConnectAction, SIGNAL(triggered()), this, SLOT(quickLogin())); - connect(m_printAction, SIGNAL(triggered()), this, SLOT(printScreen())); - connect(m_exitAction, SIGNAL(triggered()), this, SLOT(confirmExitQTerm())); - - connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copy())); - connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(paste())); - connect(m_colorCopyAction, SIGNAL(toggled(bool)), this, SLOT(copyColor(bool))); - connect(m_rectAction, SIGNAL(toggled(bool)), this, SLOT(copyRect(bool))); - connect(m_autoCopyAction, SIGNAL(toggled(bool)), this, SLOT(autoCopy(bool))); - connect(m_wwrapAction, SIGNAL(toggled(bool)), this, SLOT(wordWrap(bool))); - - connect(escapeGroup, SIGNAL(triggered(QAction*)), this, SLOT(updateESC(QAction*))); - connect(codecGroup, SIGNAL(triggered(QAction*)), this, SLOT(updateCodec(QAction*))); - - connect(m_refreshAction, SIGNAL(triggered()), this, SLOT(refresh())); - - connect(langGroup, SIGNAL(triggered(QAction*)), this, SLOT(updateLang(QAction*))); - - connect(m_uiFontAction, SIGNAL(triggered()), this, SLOT(uiFont())); - connect(m_fullAction, SIGNAL(toggled(bool)), this, SLOT(triggerFullScreen(bool))); - connect(m_menuBarAction, SIGNAL(toggled(bool)), this, SLOT(hideMenuBar(bool))); - connect(m_bossAction, SIGNAL(triggered()), this, SLOT(bosscolor())); - - connect(scrollGroup, SIGNAL(triggered(QAction*)), this, SLOT(updateScroll(QAction*))); - - connect(m_switchAction, SIGNAL(toggled(bool)), this, SLOT(updateSwitchBar(bool))); - - connect(m_currentSessionAction, SIGNAL(triggered()), this, SLOT(setting())); - connect(m_defaultAction, SIGNAL(triggered()), this, SLOT(defaultSetting())); - connect(m_prefAction, SIGNAL(triggered()), this, SLOT(preference())); - - connect(m_copyArticleAction, SIGNAL(triggered()), this, SLOT(copyArticle())); - connect(m_antiIdleAction, SIGNAL(toggled(bool)), this, SLOT(antiIdle(bool))); - connect(m_autoReplyAction, SIGNAL(toggled(bool)), this, SLOT(autoReply(bool))); - connect(m_viewMessageAction, SIGNAL(triggered()), this, SLOT(viewMessages())); - connect(m_beepAction, SIGNAL(toggled(bool)), this, SLOT(updateBeep(bool))); - connect(m_mouseAction, SIGNAL(toggled(bool)), this, SLOT(updateMouse(bool))); - connect(m_viewImageAction, SIGNAL(triggered()), this, SLOT(viewImages())); - - connect(m_scriptReloadAction, SIGNAL(triggered()), this, SLOT(reloadScript())); - connect(m_scriptRunAction, SIGNAL(triggered()), this, SLOT(runScript())); - connect(m_scriptStopAction, SIGNAL(triggered()), this, SLOT(stopScript())); - connect(m_scriptDebugAction, SIGNAL(triggered()), this, SLOT(debugConsole())); - - connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(aboutQTerm())); - connect(m_homepageAction, SIGNAL(triggered()), this, SLOT(homepage())); - - connect(m_reconnectAction, SIGNAL(toggled(bool)), this, SLOT(reconnect(bool))); - connect(m_shortcutsAction, SIGNAL(triggered()), this, SLOT(configShortcuts())); - connect(m_toolbarsAction, SIGNAL(triggered()), this, SLOT(configToolbars())); -} - -void Frame::addMainMenu() -{ - mainMenu = menuBar(); - - QMenu * file = mainMenu->addMenu(tr("File")); - file->addAction(m_connectAction); - file->addAction(m_disconnectAction); - - file->addSeparator(); - file->addAction(m_addressAction); - file->addAction(m_quickConnectAction); - file->addSeparator(); - file->addAction(m_printAction); - file->addSeparator(); - file->addAction(m_exitAction); - - //Edit Menu - QMenu * edit = new QMenu(tr("Edit"), this); - mainMenu->addMenu(edit); - - edit->addAction(m_copyAction); - edit->addAction(m_pasteAction); - edit->addSeparator(); - edit->addAction(m_colorCopyAction); - edit->addAction(m_rectAction); - edit->addAction(m_autoCopyAction); - edit->addAction(m_wwrapAction); - - QMenu * escapeMenu = new QMenu(tr("Paste &with color"), this); - escapeMenu->addAction(m_noescAction); - escapeMenu->addAction(m_escescAction); - escapeMenu->addAction(m_uescAction); - escapeMenu->addAction(m_customescAction); - edit->addMenu(escapeMenu); - - QMenu * codecMenu = new QMenu(tr("Clipboard Chinese &Conversion"), this); - codecMenu->addAction(m_NoConvAction); - codecMenu->addAction(m_S2TAction); - codecMenu->addAction(m_T2SAction); - edit->addMenu(codecMenu); - - //View menu - QMenu * view = new QMenu(tr("View"), this); - mainMenu->addMenu(view); - - view->addAction(m_refreshAction); - view->addSeparator(); - - //language menu - langMenu = new QMenu(tr("&Language"), this); - langMenu->addAction(m_engAction); - langMenu->addAction(m_chsAction); - langMenu->addAction(m_chtAction); - view->addMenu(langMenu); - view->addAction(m_uiFontAction); - - themesMenu = new QMenu(tr("&Themes"), this); - view->addMenu(themesMenu); - - view->addAction(m_bossAction); - - view->addSeparator(); - QMenu *scrollMenu = new QMenu(tr("&ScrollBar"), this); - scrollMenu->addAction(m_scrollHideAction); - scrollMenu->addAction(m_scrollLeftAction); - scrollMenu->addAction(m_scrollRightAction); - view->addMenu(scrollMenu); - view->addAction(m_switchAction); - view->addSeparator(); - view->addAction(m_menuBarAction); - view->addAction(m_fullAction); - - - // Option Menu - QMenu * option = new QMenu(tr("Option"), this); - mainMenu->addMenu(option); - - option->addAction(m_currentSessionAction); - option->addSeparator(); - option->addAction(m_defaultAction); - option->addAction(m_prefAction); - option->addSeparator(); - option->addAction(m_shortcutsAction); - option->addAction(m_toolbarsAction); - - // Special - QMenu * spec = new QMenu(tr("Special"), this); - mainMenu->addMenu(spec); - spec->addAction(m_copyArticleAction); - spec->addAction(m_antiIdleAction); - spec->addAction(m_autoReplyAction); - spec->addAction(m_viewMessageAction); - spec->addAction(m_beepAction); - spec->addAction(m_mouseAction); - spec->addAction(m_viewImageAction); - - - //Script - QMenu * script = new QMenu(tr("Script"), this); - mainMenu->addMenu(script); - script->addAction(m_scriptRunAction); - script->addAction(m_scriptStopAction); - script->addSeparator(); - script->addAction(m_scriptDebugAction); - script->addAction(m_scriptReloadAction); - - //Window menu - windowsMenu = new QMenu(tr("Windows"), this); - connect(windowsMenu, SIGNAL(aboutToShow()), - this, SLOT(windowsMenuAboutToShow())); - - mainMenu->addMenu(windowsMenu); - mainMenu->addSeparator(); - - //Help menu - QMenu * help = new QMenu(tr("Help"), this); - mainMenu->addMenu(help); - help->addAction(m_aboutAction); - help->addAction(m_homepageAction); - -} - QMenu * Frame::genPopupMenu(QWidget * owner) { QMenu * popupMenu = new QMenu(owner); - popupMenu->addAction(m_menuBarAction); - popupMenu->addAction(m_fullAction); + popupMenu->addAction(actionMenubar); + popupMenu->addAction(actionFullscreen); popupMenu->addSeparator(); - popupMenu->addAction(m_copyAction); - popupMenu->addAction(m_pasteAction); - popupMenu->addAction(m_copyArticleAction); + popupMenu->addAction(actionCopy); + popupMenu->addAction(actionPaste); + popupMenu->addAction(actionCopy_Article); popupMenu->addSeparator(); - popupMenu->addAction(m_currentSessionAction); + popupMenu->addAction(actionCurrent_Session_Setting); return popupMenu; } -void Frame::updateMenuToolBar() -{ - Window * window = qobject_cast<Window *>(m_MdiArea->activeSubWindow()); - - if (window == NULL) - return; - - m_disconnectAction->setEnabled(window->isConnected()); - - m_colorCopyAction->setChecked(window->m_bCopyColor); - m_rectAction->setChecked(window->m_bCopyRect); - m_autoCopyAction->setChecked(window->m_bAutoCopy); - m_wwrapAction->setChecked(window->m_bWordWrap); - - - m_fullAction->setChecked(Global::instance()->isFullScreen()); - - m_antiIdleAction->setChecked(window->m_bAntiIdle); - m_autoReplyAction->setChecked(window->m_bAutoReply); - m_beepAction->setChecked(window->m_bBeep); - m_mouseAction->setChecked(window->m_bMouse); - -} - -void Frame::enableMenuToolBar(bool enable) -{ - m_disconnectAction->setEnabled(enable); - m_printAction->setEnabled(enable); - - m_copyAction->setEnabled(enable); - m_pasteAction->setEnabled(enable); - m_colorCopyAction->setEnabled(enable); - m_rectAction->setEnabled(enable); - m_autoCopyAction->setEnabled(enable); - m_wwrapAction->setEnabled(enable); - - m_refreshAction->setEnabled(enable); - - m_currentSessionAction->setEnabled(enable); - - m_copyArticleAction->setEnabled(enable); - m_antiIdleAction->setEnabled(enable); - m_autoReplyAction->setEnabled(enable); - m_viewMessageAction->setEnabled(enable); - m_beepAction->setEnabled(enable); - m_mouseAction->setEnabled(enable); - -#ifdef SCRIPT_ENABLED - m_scriptReloadAction->setEnabled(enable); - m_scriptRunAction->setEnabled(enable); - m_scriptStopAction->setEnabled(enable); -#ifdef SCRIPTTOOLS_ENABLED - m_scriptDebugAction->setEnabled(enable); -#endif // SCRIPTTOOLS_ENABLED -#endif - if (enable) { - mdiconnectTools->setVisible(Global::instance()->showToolBar(mdiconnectTools->objectName())); - } else { - //FIXME: Saveing states of the toolbars only works when a window is open - Global::instance()->setShowToolBar(mdiTools->objectName(), !mdiTools->isHidden()); - Global::instance()->setShowToolBar(mdiconnectTools->objectName(),!mdiconnectTools->isHidden()); - Global::instance()->setShowToolBar(key->objectName(),!key->isHidden()); - mdiconnectTools->hide(); - } - - return; -} - void Frame::updateKeyToolBar() { - key->clear(); - key->addAction(QIcon(":/pic/keys.png"), tr("Key Setup"), this, SLOT(keySetup())); + keyToolBar->clear(); + keyToolBar->addAction(actionKey_Setup); Config * conf = Global::instance()->fileCfg(); QString strItem, strTmp; @@ -1294,16 +810,12 @@ for (int i = 0; i < num; i++) { strItem = QString("name%1").arg(i); strTmp = conf->getItemValue("key", strItem).toString(); - ToolButton *button = new ToolButton(key, i, strTmp); -// button->setUsesTextLabel(true); + ToolButton *button = new ToolButton(keyToolBar, i, strTmp); button->setText(strTmp); -// button->setTextPosition(QToolButton::BesideIcon); strItem = QString("key%1").arg(i); strTmp = (conf->getItemValue("key", strItem).toString()); -// QToolTip::add( button, strTmp.mid(1) ); -// button->addToolTip(strTmp.mid(1)); connect(button, SIGNAL(buttonClicked(int)), this, SLOT(keyClicked(int))); - key->addWidget(button); + keyToolBar->addWidget(button); } } @@ -1323,14 +835,6 @@ activateWindow(); } -QAction * Frame::insertThemeItem(const QString & themeitem) -{ - QAction * idAction = new QAction(themeitem, this); - themesMenu->addAction(idAction); - idAction->setCheckable(true); - idAction->setChecked(themeitem == theme); - return idAction; -} void Frame::setUseTray(bool use) { @@ -1476,7 +980,7 @@ } } -void Frame::configShortcuts() +void Frame::on_actionConfigure_Shortcuts_triggered() { QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); QList<QShortcut*> shortcuts = findChildren<QShortcut*>(); @@ -1488,14 +992,12 @@ void Frame::saveToolbars() { Config * conf = Global::instance()->fileCfg(); - QList<QToolBar*> toolbars = findChildren<QToolBar*>(); - QToolBar * toolbar; QSize toolButtonIconSize; - foreach (toolbar, toolbars) + foreach (QToolBar *toolbar, findChildren<QToolBar*>()) { toolButtonIconSize = toolbar->iconSize(); QStringList listActions; - if (toolbar == key) + if (toolbar == keyToolBar) continue; foreach(QAction* action, toolbar->actions()) { @@ -1523,7 +1025,7 @@ foreach (toolbar, toolbars) { QStringList actions=conf->getItemValue("ToolBars", toolbar->objectName()).toStringList(); - if (toolbar == key) + if (toolbar == keyToolBar) continue; foreach(QString action, actions) { @@ -1534,7 +1036,7 @@ toolbar->addSeparator(); else { act=findChild<QAction*>(action); - if (act != 0 && act->actionGroup()==0) + if (act != 0 ) // kingson: I forgot why && act->actionGroup()==0) toolbar->addAction(act); } } @@ -1543,7 +1045,7 @@ setIconSize(conf->getItemValue("ToolBars", "IconSize").toSize()); } -void Frame::configToolbars() +void Frame::on_actionConfigure_Toolbars_triggered() { ToolbarDialog td(this); td.exec(); @@ -1558,7 +1060,7 @@ void Frame::keyPressEvent(QKeyEvent * e) { - if (m_MdiArea->subWindowList().count() == 0 && (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { + if (mdiArea->subWindowList().count() == 0 && (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) { loadSession(); e->accept(); } else { @@ -1568,7 +1070,7 @@ void Frame::mouseReleaseEvent(QMouseEvent * e) { - if (m_MdiArea->subWindowList().count() == 0 && (e->button() == Qt::LeftButton)) { + if (mdiArea->subWindowList().count() == 0 && (e->button() == Qt::LeftButton)) { loadSession(); e->accept(); } else { @@ -1597,6 +1099,64 @@ tray->showMessage(title, message, QSystemTrayIcon::Information, millisecondsTimeoutHint); return true; } + +void Frame::groupActions() +{ + // These are actions which are enabled without any subwindow + listBasicActions + << "actionNew_Console" + << "actionQuick_Login" << "actionAddressBook" << "actionQuit" + << "actionNew_ANSI" << "actionOpen_ANSI" + << "actionFont" << "actionStatusbar" << "actionMenubar" << "actionFullscreen" + << "actionImage_Viewer" + << "actionManage_Favarites" << "actionArticle_Manager" + << "actionDefault_Session_Setting" << "actionPreference" + << "actionConfigure_Toolbars" << "actionConfigure_Shortcuts" << "actionKey_Setup" + << "actionQTerm_Online" << "actionContents" <<"actionWhat_s_this" + << "actionAbout_QTerm" << "actionAbout_Qt"; + QActionGroup *group; + // These actions belong to Edit->Past with Color submenu + group = new QActionGroup(this); + group->addAction(actionNone_Color); + group->addAction(actionESC_ESC); + group->addAction(actionCtrl_U); + group->addAction(actionCustom); + connect(group, SIGNAL(triggered(QAction*)), this, SLOT(updateESC(QAction*))); + // These actions belong to Edit->Clipboard Conversion submenu + group = new QActionGroup(this); + group->addAction(actionNone); + group->addAction(actionCHS_CHT); + group->addAction(actionCHT_CHS); + connect(group, SIGNAL(triggered(QAction*)), this, SLOT(updateCodec(QAction*))); + // These actions belong to View->Scrollbar submenu + group = new QActionGroup(this); + group->addAction(actionScroll_Hide); + group->addAction(actionScroll_Left); + group->addAction(actionScroll_Right); + connect(group, SIGNAL(triggered(QAction*)), this, SLOT(updateScroll(QAction*))); + // These actions belong to View->Language submenu + group = new QActionGroup(this); + group->addAction(actionEnglish); + group->addAction(actionSimplified_Chinese); + group->addAction(actionTraditional_Chinese); + connect(group, SIGNAL(triggered(QAction*)), this, SLOT(updateLang(QAction*))); + + // The other actions are grouped and redirected to subwindow + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + + actionsExtra = new QActionGroup(this); + actionsExtra->setExclusive(false); + connect(actionsExtra, SIGNAL(triggered(QAction*)), + this, SLOT(actionsDispatcher(QAction*))); + + foreach(QAction* action, actions) { + action->setVisible(listBasicActions.contains(action->objectName()) + || action->actionGroup() != 0); + if (action->actionGroup() == 0) + actionsExtra->addAction(action); + } } +} + #include <qtermframe.moc> Modified: trunk/qterm-qt4/src/qtermglobal.cpp =================================================================== --- trunk/qterm-qt4/src/qtermglobal.cpp 2010-06-18 15:00:23 UTC (rev 1199) +++ trunk/qterm-qt4/src/qtermglobal.cpp 2010-07-01 09:12:56 UTC (rev 1200) @@ -59,14 +59,20 @@ } Global::Global() - : m_fileCfg("./qterm.cfg"), m_addrCfg("./address.cfg"), m_pathLib("./"), m_pathCfg("./"), m_windowState(), m_status(INIT_OK), m_style(), m_fullScreen(false), m_language(Global::English), m_showToolBar() + : m_fileCfg("./qterm.cfg"), m_addrCfg("./address.cfg"), + m_pathLib("./"), m_pathCfg("./"), + m_windowState(), m_status(INIT_OK), m_style(), + m_fullScreen(false), m_language(Global::English) { if (!iniWorkingDir(qApp->arguments()[0])) { m_status = INIT_ERROR; return; } - m_config = new Config(m_fileCfg); - m_address = new Config(m_addrCfg); + m_translatorQT = new QTranslator(0); + m_translatorQTerm = new QTranslator(0); + + m_config = new Config(m_fileCfg); + m_address = new Config(m_addrCfg); m_converter = new Convert(); #ifdef KWALLET_ENABLED if (Wallet::isWalletAvailable()) { @@ -352,42 +358,33 @@ void Global::loadPrefence() { QString strTmp; - strTmp = m_config->getItemValue("preference", "xim").toString(); - m_pref.XIM = (Global::Conversion)strTmp.toInt(); - strTmp = m_config->getItemValue("preference", "wordwrap").toString(); - m_pref.nWordWrap = strTmp.toInt(); - strTmp = m_config->getItemValue("preference", "wheel").toString(); - m_pref.bWheel = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "url").toString(); - m_pref.bUrl = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "blinktab").toString(); - m_pref.bBlinkTab = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "warn").toString(); - m_pref.bWarn = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "beep").toString(); - m_pref.nBeep = strTmp.toInt(); + + m_pref.XIM = (Global::Conversion)m_config->getItemValue("preference", "xim").toInt(); + m_pref.nWordWrap = m_config->getItemValue("preference", "wordwrap").toInt(); + m_pref.bWheel = m_config->getItemValue("preference", "wheel").toBool(); + m_pref.bUrl = m_config->getItemValue("preference", "url").toBool(); + m_pref.bBlinkTab = m_config->getItemValue("preference", "blinktab").toBool(); + m_pref.bWarn = m_config->getItemValue("preference", "warn").toBool(); + m_pref.nBeep = m_config->getItemValue("preference", "beep").toInt(); m_pref.strWave = m_config->getItemValue("preference", "wavefile").toString(); - strTmp = m_config->getItemValue("preference", "http").toString(); - m_pref.strHttp = strTmp; - strTmp = m_config->getItemValue("preference", "antialias").toString(); - m_pref.bAA = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "tray").toString(); - m_pref.bTray = (strTmp != "0"); - strTmp = m_config->getItemValue("preference", "externalplayer").toString(); - m_pref.strPlayer = strTmp; + m_pref.strHttp = m_config->getItemValue("preference", "http").toString(); + m_pref.bAA = m_config->getItemValue("preference", "antialias").toBool(); + m_pref.bTray = m_config->getItemValue("preference", "tray").toBool(); + m_pref.strPlayer = m_config->getItemValue("preference", "externalplayer").toString(); + m_pref.strImageViewer = m_config->getItemValue("preference", "image").toString(); + m_pref.bClearPool = m_config->getItemValue("preference", "clearpool").toBool(); - strTmp = m_config->getItemValue("preference", "clearpool").toString(); - m_pref.bClearPool = (strTmp != "0"); strTmp = m_config->getItemValue("preference", "pool").toString(); m_pref.strPoolPath = strTmp.isEmpty() ? Global::instance()->pathCfg() + "pool/" : strTmp; if (m_pref.strPoolPath.right(1) != "/") m_pref.strPoolPath.append('/'); - strTmp = m_config->getItemValue("preference", "zmodem").toString(); - m_pref.strZmPath = strTmp.isEmpty() ? Global::instance()->pathCfg() + "zmodem/" : strTmp; + + strTmp = m_config->getItemValue("preference", "zmodem").toString(); + m_pref.strZmPath = strTmp.isEmpty() ? Global::instance()->pathCfg() + "zmodem/" : strTmp; if (m_pref.strZmPath.right(1) != "/") m_pref.strZmPath.append('/'); - strTmp = m_config->getItemValue("preference", "image").toString(); - m_pref.strImageViewer = strTmp; + + } QString Global::getOpenFileName(const QString & filter, QWidget * widget) @@ -540,35 +537,12 @@ { //install the translator QString lang = m_config->getItemValue("global", "language").toString(); - if (lang == "eng") - m_language = Global::English; - else if (lang == "chs") - m_language = Global::SimpilifiedChinese; + Global::Language language = Global::English; + if (lang == "chs") + language = Global::SimplifiedChinese; else if (lang == "cht") - m_language = Global::TraditionalChinese; - else { - qDebug("Language setting is not correct"); - m_language = Global::English; - } - if (lang != "eng" && !lang.isEmpty()) { - QString qt_qm; - if (lang == "chs") - qt_qm = QLibraryInfo::location(QLibraryInfo::TranslationsPath)+"/qt_zh_CN.qm"; - else - qt_qm = QLibraryInfo::location(QLibraryInfo::TranslationsPath)+"/qt_zh_TW.qm"; - - static QTranslator * translator = new QTranslator(0); - translator->load(qt_qm); - qApp->installTranslator(translator); - - // look in $HOME/.qterm/po/ first - QString qterm_qm = QDir::homePath() + "/.qterm/po/qterm_" + lang + ".qm"; - if (!QFile::exists(qterm_qm)) - qterm_qm = m_pathLib + "po/qterm_" + lang + ".qm"; - translator = new QTranslator(0); - translator->load(qterm_qm); - qApp->installTranslator(translator); - } + language = Global::TraditionalChinese; + setLanguage(language); //set font QString family = m_config->getItemValue("global", "font").toString(); QString pointsize = m_config->getItemValue("global", "pointsize").toString(); @@ -590,10 +564,8 @@ return false; QString pathPool = m_config->getItemValue("preference", "pool").toString(); - if (pathPool.isEmpty()) pathPool = m_pathCfg + "pool/"; - if (pathPool.right(1) != "/") pathPool.append('/'); @@ -676,6 +648,16 @@ return m_switchBar; } +bool Global::showStatusBar() const +{ + return m_statusBar; +} + +bool Global::showMenuBar() const +{ + return m_menuBar; +} + void Global::setClipConversion(Global::Conversion conversionId) { m_clipConversion = conversionId; @@ -696,6 +678,11 @@ m_statusBar = isShow; } +void Global::setMenuBar(bool isShow) +{ + m_menuBar = isShow; +} + void Global::setBossColor(bool isBossColor) { m_bossColor = isBossColor; @@ -714,6 +701,37 @@ void Global::setLanguage(Global::Language language) { m_language = language; + // unload previous translation + if (!m_translatorQT->isEmpty()) + qApp->removeTranslator(m_translatorQT); + if (!m_translatorQTerm->isEmpty()) + qApp->removeTranslator(m_translatorQTerm); + // check new translation files + QString qt_qm, qterm_qm; + switch(language) + { + case Global::SimplifiedChinese: + qt_qm = QLibraryInfo::location(QLibraryInfo::TranslationsPath)+"/qt_zh_CN.qm"; + qterm_qm = m_pathCfg + "/po/qterm_chs.qm"; + if (!QFile::exists(qterm_qm)) + qterm_qm = m_pathLib + "po/qterm_chs.qm"; + + break; + case Global::TraditionalChinese: + qt_qm = QLibraryInfo::location(QLibraryInfo::Trans... [truncated message content] |