📄 chatwgt.cpp
字号:
show(); if(windowState() & Qt::WindowMaximized) this->setWindowState(Qt::WindowMaximized|Qt::WindowActive); else if(windowState () & Qt::WindowMinimized) { this->setWindowState(Qt::WindowNoState); this->setWindowState(Qt::WindowActive ); } else this->setWindowState(Qt::WindowActive);}//\*****************************************************************************void ChatWgt::slot_sendFile(quint64 uid){ QString filename; filename = QFileDialog::getOpenFileName( this, tr("Choose a file to open"), "/" ""); qDebug("[ChatWgt::slot_sendFile]: filename = %s", filename.toLocal8Bit().data()); if(filename.isEmpty()) return; FileTransferWgt* ftw = new FileTransferWgt(filename, 0); quint32 id = m_chatCore->initSendingFile(uid, filename, ftw); UserInfo* info = m_chatCore->getUserInfo(uid); if(info) { ftw->setUserName(info->nickname()); ftw->setIp(info->ip()); } if(id) { ftw->setID(id); ftw->setUid(uid); } ftw->init();}//\*****************************************************************************void ChatWgt::slot_receiveFile(const QString & filename, quint16 ID, quint64 srcIP){ FileTransferWgt* ftw = new FileTransferWgt(filename, 1); UserInfo* info = m_chatCore->getUserInfo(srcIP); if(info) { ftw->setUserName(info->nickname()); ftw->setIp(info->ip()); } ftw->setID (ID ); ftw->setUid(srcIP); ftw->init(); m_chatCore->initReceivingFile(ftw);}//\*****************************************************************************void ChatWgt::slot_openSocketError(quint16 port){ mw_log->addError(QString("Couldn't open UDP socket on port %1 ").arg(port));}//\*****************************************************************************void ChatWgt::slot_exit(){ foreach(ChannelWgt* cw, mw_channels) cw->slot_disconnected(); m_chatCore->stopThreads(); m_chatCore->saveSettings(true); QApplication::quit();}//\*****************************************************************************void ChatWgt::slot_trayIconClicked(QSystemTrayIcon::ActivationReason reason){ ChannelWgt* chnnl = findChannel(currentChannelName()); if(reason == QSystemTrayIcon::Trigger) { m_trayIcon->setStaticIcon(QChatIcon::iconPath("tray-icon")); if(isHidden() || windowState () & Qt::WindowMinimized) { show(); if(windowState() & Qt::WindowMaximized) setWindowState(Qt::WindowMaximized|Qt::WindowActive); else setWindowState(Qt::WindowNoState); if(chnnl) chnnl->setFocus2InputText(); } else hide(); }}//\*****************************************************************************void ChatWgt::slot_showSmiles(){ if(!mw_smiles || !mw_smiles->inited()) return; if(m_smilesScrllArea->isHidden()) { mw_smiles->setOptimalSize(); mw_smiles->unselectAll(); QDesktopWidget dsctp; int wd = mw_smiles->width(); int he = mw_smiles->height(); int max_wd, max_he; max_wd = (dsctp.availableGeometry().width() / 8) * 7; max_he = (dsctp.availableGeometry().height() / 8) * 7; if(wd > max_wd) wd = max_wd; if(he > max_he) he = max_he; m_smilesScrllArea->setWindowFlags(Qt::FramelessWindowHint | m_smilesScrllArea->windowFlags() | Qt::WindowStaysOnTopHint); m_smilesScrllArea->resize(wd + 5, he + 5); m_smilesScrllArea->move(QCursor().pos()); m_smilesScrllArea->show(); mw_smiles->show(); if(wd >= mw_smiles->width()) m_smilesScrllArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); else m_smilesScrllArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); if(he >= mw_smiles->height()) m_smilesScrllArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); else m_smilesScrllArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); } else m_smilesScrllArea->hide();}//\*****************************************************************************void ChatWgt::slot_insertSmile(const QString & smile){ ChannelWgt* chnnl = qobject_cast<ChannelWgt*>(mw_tabs->currentWidget()); if(chnnl) chnnl->inputText()->append(smile);}//\*****************************************************************************QString ChatWgt::currentChannelName() const{ ChannelWgt* chnnl = qobject_cast<ChannelWgt*>(mw_tabs->currentWidget()); return (chnnl ? chnnl->name() : "");}//\*****************************************************************************void ChatWgt::fillProfilesCmbx(const QStringList & profiles, const QString & current){ disconnect(m_profilesCmbx, SIGNAL(currentIndexChanged(const QString &)), m_chatCore , SLOT (slot_loadProfile (const QString &))); QStringList::const_iterator i; QStringList::const_iterator end = profiles.constEnd(); int idx; for(i = profiles.constBegin(); i != end; ++i) m_profilesCmbx->addItem(*i); if((idx = m_profilesCmbx->findText(current)) >= 0) m_profilesCmbx->setCurrentIndex(idx); connect(m_profilesCmbx, SIGNAL(currentIndexChanged(const QString &)), m_chatCore , SLOT (slot_loadProfile (const QString &)));}//\*****************************************************************************void ChatWgt::slot_setCurrentProfileName(const QString & name){ int idx; if((idx = m_profilesCmbx->findText(name)) >= 0) m_profilesCmbx->setCurrentIndex(idx); else m_profilesCmbx->addItem(name); if((idx = m_profilesCmbx->findText(name)) >= 0) m_profilesCmbx->setCurrentIndex(idx);}void ChatWgt::slot_reloadProfileData(){ if(!m_userInfoDlg->isHidden() && !m_userInfoDlg->readOnly()) m_userInfoDlg->slot_loadInfo(UserInfo::myInfo()); if(!m_preferencesDlg->isHidden()) m_preferencesDlg->init(); ChatTextWgt::initSmiles(QChatSettings::settings()->smilesThemePath()); mw_smiles->loadTheme(QChatSettings::settings()->smilesThemePath()); // FIXME incorrect works if other channel set its status in myInfo foreach(ChannelWgt* cw, mw_channels) m_chatCore->slot_statusAnswer(cw->name(), QChatSettings::settings()->broadcast().toIPv4Address(), AbstractChatCore::Common, 0, 1); m_preferencesDlg->setIconFormat(*QChatSettings::settings()->iconFormat()); changeIconFormat(*QChatSettings::settings()->iconFormat());}void ChatWgt::createActions(){ m_showSettingsAct = new QAction(this); m_showPreferencesAct = new QAction(this); m_exitAct = new QAction(this); m_showSmilesAct = new QAction(this); m_showEditShortcutsAct = new QAction(this); m_addChannelAct = new QAction(this); m_delChannelAct = new QAction(this); m_aboutAct = new QAction(this); m_aboutQtAct = new QAction(this); m_licenseAct = new QAction(this); m_writeSettingsAct = new QAction(this); m_addProfileAct = new QAction(this); m_deleteProfileAct = new QAction(this); m_renameProfileAct = new QAction(this); (m_translateEnAct = new QAction(this))->setData("en"); (m_translatePlAct = new QAction(this))->setData("pl"); (m_translateRuAct = new QAction(this))->setData("ru"); (m_translateUkAct = new QAction(this))->setData("uk"); (m_translateEsAct = new QAction(this))->setData("es"); (m_translateDeAct = new QAction(this))->setData("de"); (m_translateSrAct = new QAction(this))->setData("sr"); (m_showMainTBarAct = new QAction(this))->setCheckable(true); (m_showProfilesTBarAct = new QAction(this))->setCheckable(true); (m_showPluginsTBarAct = new QAction(this))->setCheckable(true); (m_showFormattingTBarAct = new QAction(this))->setCheckable(true); m_showSingleMessagesAct= new QAction(this); m_showPluginsAct = new QAction(this); m_broadcastMessageAct = new QAction(this); (m_setServerModeAct = new QAction(this))->setCheckable(true); (m_setServerlessModeAct = new QAction(this))->setCheckable(true); m_connectToServerAct = new QAction(this); m_disconnectFromServerAct = new QAction(this); (m_toolButtonsSizeDefault = new QAction(this))->setData(0); (m_toolButtonsSize16 = new QAction(this))->setData(16); (m_toolButtonsSize24 = new QAction(this))->setData(24); (m_toolButtonsSize32 = new QAction(this))->setData(32); (m_toolButtonsSize48 = new QAction(this))->setData(48); QActionGroup* tbSizeGroup = new QActionGroup(this); m_toolButtonsSizeDefault->setCheckable(true); m_toolButtonsSize16 ->setCheckable(true); m_toolButtonsSize24 ->setCheckable(true); m_toolButtonsSize32 ->setCheckable(true); m_toolButtonsSize48 ->setCheckable(true); m_toolButtonsSizeDefault->setActionGroup(tbSizeGroup); m_toolButtonsSize16 ->setActionGroup(tbSizeGroup); m_toolButtonsSize24 ->setActionGroup(tbSizeGroup); m_toolButtonsSize32 ->setActionGroup(tbSizeGroup); m_toolButtonsSize48 ->setActionGroup(tbSizeGroup); m_disconnectFromServerAct->setVisible(false); m_setServerModeAct ->setData(ChatCore::Server); m_setServerlessModeAct->setData(ChatCore::Serverless); QActionGroup* actGrp = new QActionGroup(this); actGrp->addAction(m_setServerModeAct); actGrp->addAction(m_setServerlessModeAct); m_menuFile->addAction(m_connectToServerAct); m_menuFile->addAction(m_disconnectFromServerAct); m_menuFile->addAction(m_setServerModeAct); m_menuFile->addAction(m_setServerlessModeAct); m_menuFile->addSeparator(); m_menuTranslations->addAction(m_translateEnAct); m_menuTranslations->addAction(m_translateDeAct); m_menuTranslations->addAction(m_translatePlAct); m_menuTranslations->addAction(m_translateRuAct); m_menuTranslations->addAction(m_translateSrAct); m_menuTranslations->addAction(m_translateEsAct); m_menuTranslations->addAction(m_translateUkAct); m_menuFile ->addAction(m_broadcastMessageAct); m_menuFile ->addAction(m_addChannelAct); m_menuFile ->addAction(m_delChannelAct); m_menuFile ->addAction(m_exitAct); m_menuSettings->addAction(m_showSettingsAct); m_menuSettings->addAction(m_showPreferencesAct);// m_menuSettings->addAction(m_writeSettingsAct); m_menuSettings->addAction(m_showEditShortcutsAct); m_menuSettings->addMenu (m_menuTranslations); m_menuSettings->addMenu (m_menuToolbars); m_menuView ->addAction(m_showSmilesAct); m_menuView ->addAction(m_showSingleMessagesAct); m_menuView ->addAction(m_showPluginsAct); m_menuHelp ->addAction(m_aboutAct); m_menuHelp ->addAction(m_aboutQtAct); m_menuHelp ->addAction(m_licenseAct); m_menuToolbars->addAction(m_showMainTBarAct); m_menuToolbars->addAction(m_showProfilesTBarAct); m_menuToolbars->addAction(m_showPluginsTBarAct); m_menuToolbars->addAction(m_showFormattingTBarAct); m_menuBar ->addMenu(m_menuFile); m_menuBar ->addMenu(m_menuView); m_menuBar ->addMenu(m_menuSettings); m_menuBar ->addMenu(m_menuHelp); connect(m_showSettingsAct , SIGNAL(triggered(bool)), this , SLOT(slot_showSettings())); connect(m_showPreferencesAct , SIGNAL(triggered(bool)), this , SLOT(slot_showPreferences())); connect(m_exitAct , SIGNAL(triggered(bool)), this , SLOT(slot_exit())); connect(m_showSmilesAct , SIGNAL(triggered(bool)), this , SLOT(slot_showSmiles())); connect(m_showEditShortcutsAct, SIGNAL(triggered(bool)), this , SLOT(showConfigureShortcuts())); connect(m_addChannelAct , SIGNAL(triggered(bool)), m_addChannelDlg , SLOT(getValues())); connect(m_delChannelAct , SIGNAL(triggered(bool)), this , SLOT(slot_delChannell())); connect(m_aboutAct , SIGNAL(triggered(bool)), this , SLOT(slot_about())); connect(m_aboutQtAct , SIGNAL(triggered(bool)), this , SLOT(slot_aboutQt())); connect(m_licenseAct , SIGNAL(triggered(bool)), this , SLOT(slot_license())); connect(m_writeSettingsAct , SIGNAL(triggered(bool)), m_chatCore , SLOT(slot_saveSettings())); connect(m_renameProfileAct , SIGNAL(triggered(bool)), this , SLOT(slot_editProfileName())); connect(m_addProfileAct , SIGNAL(triggered(bool)), this , SLOT(slot_addProfile())); connect(m_deleteProfileAct , SIGNAL(triggered(bool)), this , SLOT(slot_delProfile())); connect(m_showMainTBarAct , SIGNAL(triggered(bool)), m_mainToolBar , SLOT(setVisible(bool))); connect(m_showProfilesTBarAct , SIGNAL(triggered(bool)), m_profilesToolBar , SLOT(setVisible(bool))); connect(m_showPluginsTBarAct , SIGNAL(triggered(bool)), m_pluginsToolBar , SLOT(setVisible(bool))); connect(m_showFormattingTBarAct, SIGNAL(triggered(bool)), m_formattingToolBar, SLOT(setVisible(bool))); connect(m_showSingleMessagesAct, SIGNAL(triggered(bool)), this , SLOT(slot_showSingleMessagesHistory())); connect(m_showPluginsAct , SIGNAL(triggered(bool)), this , SLOT(showPlugins())); connect(m_broadcastMessageAct , SIGNAL(triggered(bool)), this , SLOT(sendBroadcastMessage())); connect(m_translatePlAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateUkAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateRuAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateEnAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateEsAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateDeAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_translateSrAct , SIGNAL(triggered(bool)), this , SLOT(setLanguage())); connect(m_setServerlessModeAct, SIGNAL(triggered(bool)), this , SLOT(setMode())); connect(m_setServerModeAct , SIGNAL(triggered(bool)), this , SLOT(setMode())); connect(m_setServerModeAct , SIGNAL(triggered(bool)), this, SLOT(chvisConnectToServerAct())); connect(m_setServerlessModeAct, SIGNAL(triggered(bool)), this, SLOT(chvisConnectToServerAct())); connect(m_connectToServerAct , SIGNAL(triggered(bool)), this, SLOT(connect2server())); connect(m_disconnectFromServerAct, SIGNAL(triggered(bool)), this, SLOT(disconnectFromServer())); connect(m_toolButtonsSizeDefault , SIGNAL(triggered(bool)), this, SLOT(setToolbarsIconsSize())); connect(m_toolButtonsSize16 , SIGNAL(triggered(bool)), this, SLOT(setToolbarsIconsSize())); connect(m_toolButtonsSize24 , SIGNAL(triggered(bool)), this, SLOT(setToolbarsIconsSize())); connect(m_toolButtonsSize32 , SIGNAL(triggered(bool)), this, SLOT(setToolbarsIconsSize())); connect(m_toolButtonsSize48 , SIGNAL(triggered(bool)), this, SLOT(setToolbarsIconsSize())); connect(m_preferencesDlg , SIGNAL(wantChangeProtocol(uint)), m_chatCore, SLOT(changeProtocolVersion(uint)));}void ChatWgt::createWidgets(){ m_profilesLab = new QLabel(this); m_pluginsTabs = new QTabWidget(this); m_widgetsStack = new QStackedWidget(this); mw_tabs = new QTabWidget (this); m_addChannelBtn = new QToolButton(mw_tabs); m_delChannelBtn = new QToolButton(mw_tabs); m_addChannelDlg = new AddChannelDlg(this); m_userInfoDlg = new EditUserInfoDlg (0); m_preferencesDlg = new PreferencesDlg (this); mw_log = new LogWgt(this); mw_smiles = new SmilesWgt; m_trayIcon = new QChatTrayIcon(QChatIcon::icon("tray-icon"), this); m_profilesCmbx = new QComboBox(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -