⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatwgt.cpp

📁 用qt4 编写的局域网聊天工具
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  m_menuBar              = new QMenuBar   (this);  (m_mainToolBar         = new QToolBar   (this))->setObjectName("Main Toolbar");  (m_profilesToolBar     = new QToolBar   (this))->setObjectName("Profiles Toolbar");  (m_pluginsToolBar      = new QToolBar   (this))->setObjectName("Plugins Toolbar");  (m_formattingToolBar   = new FormattingToolBar(this))->setObjectName("Formatting Toolbar");  m_menuFile             = new QMenu      (this);  m_menuView             = new QMenu      (this);  m_menuSettings         = new QMenu      (this);  m_menuHelp             = new QMenu      (this);  m_menuTranslations     = new QMenu      (this);  m_menuToolbars         = new QMenu      (this);  m_smilesScrllArea      = new QScrollArea(0);  m_smhView              = new SingleMsgsHistoryView(0);  m_smhView->setModel(m_chatCore->smhModel());  m_smhView->resizeColumnToContents(0);  m_smhView->resizeColumnToContents(1);  m_smhView->resizeColumnToContents(2);  m_smhView->resizeColumnToContents(3);  m_smhView->resize(800, 600);  setStatusBar(new QStatusBar(this));  statusBar()->setSizeGripEnabled(false);  m_profilesCmbx->setMinimumWidth(150);  m_smilesScrllArea->setWidget(mw_smiles);  m_smilesScrllArea->resize(400, 400);  connect(m_preferencesDlg, SIGNAL(portChanged  (int)),          m_chatCore      , SLOT  (slot_bindInputPort(int)));  connect(m_preferencesDlg, SIGNAL(wantChangeSmileTheme (const QString &)),          this            , SLOT  (slot_changeSmileTheme(const QString &)));  connect(m_preferencesDlg, SIGNAL(styleSheetChanged(QString)),          this            , SIGNAL(wantChangeStyleSheet(QString)));  connect(m_preferencesDlg, SIGNAL(accepted()),          m_chatCore      , SLOT  (slot_saveSettings()));  connect(m_userInfoDlg   , SIGNAL(accepted()),          m_chatCore      , SLOT  (slot_saveSettings()));  connect(m_userInfoDlg   , SIGNAL(wantChangeNickname(QString)),          m_chatCore      , SLOT  (changeLogin(QString)));  connect(mw_smiles      , SIGNAL(smileClicked(const QString &)), this, SLOT(slot_insertSmile(const QString &)));  connect(mw_smiles      , SIGNAL(wantHide())      , m_smilesScrllArea, SLOT(hide()));  connect(m_addChannelDlg, SIGNAL(dataAccepted(const QString &)), this, SLOT(slot_addChannell(const QString &)));  connect(m_trayIcon     , SIGNAL(activated           (QSystemTrayIcon::ActivationReason)),          this           , SLOT  (slot_trayIconClicked(QSystemTrayIcon::ActivationReason)));  connect(m_smhView      , SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(showSingleMessage(const QModelIndex &)));//   connect(m_pluginsTabs, SIGNAL(currentChanged(int)), this, SLOT(pluginSwitched()));  connect(mw_tabs      , SIGNAL(currentChanged(int)), this, SLOT(pluginSwitched()));}void ChatWgt::setupLayout(){  mw_tabs->setCornerWidget (m_addChannelBtn, Qt::TopLeftCorner);  mw_tabs->setCornerWidget (m_delChannelBtn, Qt::TopRightCorner);  m_addChannelBtn->setDefaultAction(m_addChannelAct);  m_delChannelBtn->setDefaultAction(m_delChannelAct);  m_mainToolBar->addAction(m_showSmilesAct);  m_mainToolBar->addAction(m_showSettingsAct);  m_mainToolBar->addAction(m_showPreferencesAct);//   m_mainToolBar->addAction(m_writeSettingsAct);  m_profilesToolBar->addWidget(m_profilesLab);  m_profilesToolBar->addAction(m_addProfileAct);  m_profilesToolBar->addWidget(m_profilesCmbx);  m_profilesToolBar->addAction(m_renameProfileAct);  m_profilesToolBar->addAction(m_deleteProfileAct);  m_widgetsStack->insertWidget(0, mw_tabs);  m_widgetsStack->insertWidget(1, m_pluginsTabs);  setMenuBar(m_menuBar);  addToolbar(m_mainToolBar);  addToolbar(m_profilesToolBar);  addToolbar(m_pluginsToolBar);  addToolbar(m_formattingToolBar);  setCentralWidget(m_widgetsStack);}void ChatWgt::slot_editProfileName(){  bool ok;  QString str = QInputDialog::getText(this,                                      QString(tr("Input new name for '%1'")).arg(m_profilesCmbx->currentText()),                                      tr("New name:"),                                      QLineEdit::Normal,                                      m_profilesCmbx->currentText(),                                      &ok);  if(ok && !str.isEmpty() && (m_profilesCmbx->findText(str) < 0) )  {    emit wantRenameProfile(m_profilesCmbx->currentText(), str);    m_profilesCmbx->setItemText(m_profilesCmbx->currentIndex(), str);  }}void ChatWgt::slot_addProfile(){  bool ok;  QString str = QInputDialog::getText(this,                                      tr("Input name for new profile"),                                      tr("New profile name:"),                                      QLineEdit::Normal,                                      "",                                      &ok);  if(ok && !str.isEmpty() && (m_profilesCmbx->findText(str) < 0) )  {    emit wantLoadProfile(str);    m_profilesCmbx->addItem(str);    m_profilesCmbx->setCurrentIndex(m_profilesCmbx->findText(str));  }}void ChatWgt::slot_delProfile(){  if(m_profilesCmbx->count() > 1)  {     QMessageBox* msgbx;     int ans;     msgbx = new QMessageBox(tr("Are you sure?"),                             tr("Are you sure you want delete profile %1?").arg(m_profilesCmbx->currentText()),                             QMessageBox::Question, QMessageBox::Yes, QMessageBox::No, 0, this, 0);     ans = msgbx->exec();     delete msgbx;     if(ans == QMessageBox::No)       return;     emit wantDeleteProfile(m_profilesCmbx->currentText());     m_profilesCmbx->removeItem(m_profilesCmbx->currentIndex());  }}void ChatWgt::retranslate(){  m_showSettingsAct    ->setText(tr("&Edit User Details..."));  m_showPreferencesAct ->setText(tr("&Configure QChat..."      ));  m_exitAct            ->setText(tr("&Exit"                ));  m_showSmilesAct      ->setText(tr("&Show Smiles.."       ));  m_addChannelAct      ->setText(tr("&Add Channel.."       ));  m_delChannelAct      ->setText(tr("&Delete Channel.."    ));  m_aboutAct           ->setText(tr("&About"               ));  m_aboutQtAct         ->setText(tr("About &Qt"            ));  m_licenseAct         ->setText(tr("&License"             ));//   m_writeSettingsAct   ->setText(tr("&Write Settings"      ));  m_showEditShortcutsAct->setText(tr("Configure Shortcuts..."));  m_showMainTBarAct      ->setText(tr("Main Toolbar"         ));  m_showProfilesTBarAct  ->setText(tr("Profiles Toolbar"     ));  m_showPluginsTBarAct   ->setText(tr("Plugins Toolbar"      ));  m_showFormattingTBarAct->setText(tr("Formatting Toolbar"      ));  m_addProfileAct        ->setText(tr("Add pro&file..."      ));  m_deleteProfileAct     ->setText(tr("Delete p&rofile..."   ));  m_renameProfileAct     ->setText(tr("&Rename profile..."   ));  m_showSingleMessagesAct->setText(tr("Show Single Messages History..."));  m_showPluginsAct       ->setText(tr("Show Plugins"));  m_broadcastMessageAct  ->setText(tr("Send Broadcast Message..."));  m_mainToolBar        ->setWindowTitle(tr("Main Toolbar"    ));  m_profilesToolBar    ->setWindowTitle(tr("Profiles Toolbar"));  m_pluginsToolBar     ->setWindowTitle(tr("Plugins Toolbar"));  m_smhView            ->setWindowTitle(tr("Single Messages History"));  m_menuFile           ->setTitle(tr("&Chat"    ));  m_menuView           ->setTitle(tr("&View"    ));  m_menuSettings       ->setTitle(tr("&Settings"));  m_menuHelp           ->setTitle(tr("&Help"    ));  m_menuTranslations   ->setTitle(tr("&Language"));  m_menuToolbars       ->setTitle(tr("Toolbars" ));  m_translatePlAct     ->setText(tr("Polish"));  m_translateUkAct     ->setText(tr("Ukrainian"));  m_translateRuAct     ->setText(tr("Russian"));  m_translateEnAct     ->setText(tr("English"));  m_translateEsAct     ->setText(tr("Spanish"));  m_translateDeAct     ->setText(tr("German"));  m_translateSrAct     ->setText(tr("Serbian"));  m_connectToServerAct     ->setText(tr("Connect to server.."));  m_disconnectFromServerAct->setText(tr("Disconnect from server"));  m_setServerModeAct       ->setText(tr("Server Mode"));  m_setServerlessModeAct   ->setText(tr("Serverless Mode"));  m_profilesLab        ->setText(tr("Current profile:"));  m_toolButtonsSizeDefault->setText(tr("Default"));  m_toolButtonsSize16     ->setText(tr("16x16"));  m_toolButtonsSize24     ->setText(tr("24x24"));  m_toolButtonsSize32     ->setText(tr("32x32"));  m_toolButtonsSize48     ->setText(tr("48x48"));  updateShortcuts();}void ChatWgt::setLanguage(){  QString lang = ((QAction*)sender())->data().toString();  m_chatCore->setLang(lang);#if defined(Q_OS_LINUX)  QDir dir(QCoreApplication::applicationDirPath() + "/../share/qchat/translations");#else  QDir dir(QCoreApplication::applicationDirPath() + "/translations");#endif  if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", QChatSettings::settings()->settingsDir()))    if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", dir.path()))      if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", "/usr/share/qchat/translations/"))        m_translator->load("qchat_" + m_chatCore->lang() + ".qm", "/usr/local/share/qchat/translations/");  QApplication::installTranslator(m_translator);  retranslate();}void ChatWgt::slot_changeSmileTheme(const QString & path){  qDebug("[ChatWgt::slot_changeSmileTheme]: path = %s", path.toLocal8Bit().data());  if(path != QChatSettings::settings()->smilesThemePath())  {    QChatSettings::settings()->setSmilesThemePath(path);    ChatTextWgt::initSmiles(path);    mw_smiles->loadTheme(path);  }}QMenu* ChatWgt::createPopupMenu(){  QMenu* menu    = new QMenu(this);  QMenu* menu_tb = new QMenu(tr("Toolbars"), menu);  QMenu* menu_sz = new QMenu(tr("Icons Size"), menu);  menu_tb->addAction(m_showMainTBarAct);  menu_tb->addAction(m_showProfilesTBarAct);  if(!m_hidePlugins)    menu_tb->addAction(m_showPluginsTBarAct);  menu_tb->addAction(m_showFormattingTBarAct);  menu_sz->addAction(m_toolButtonsSizeDefault);  menu_sz->addAction(m_toolButtonsSize16);  menu_sz->addAction(m_toolButtonsSize24);  menu_sz->addAction(m_toolButtonsSize32);  menu_sz->addAction(m_toolButtonsSize48);  menu->addMenu(menu_tb);  menu->addMenu(menu_sz);  return menu;}void ChatWgt::restoreAndShow(){  QMessageBox::StandardButton ans;  QString msg;  restoreState(m_chatCore->state());  if(!m_chatCore->geometry().isEmpty())    restoreGeometry(m_chatCore->geometry());  else    resize(800, 600);  show();  m_showMainTBarAct      ->setChecked(m_mainToolBar      ->isVisible());  m_showProfilesTBarAct  ->setChecked(m_profilesToolBar  ->isVisible());  m_showPluginsTBarAct   ->setChecked(m_pluginsToolBar   ->isVisible());  m_showFormattingTBarAct->setChecked(m_formattingToolBar->isVisible());  // restoring tool buttons size  int sz = QChatSettings::settings()->toolbarIconsSize();  switch(sz)  {    case 16 : m_toolButtonsSize16->setChecked(true); break;    case 24 : m_toolButtonsSize24->setChecked(true); break;    case 32 : m_toolButtonsSize32->setChecked(true); break;    case 48 : m_toolButtonsSize48->setChecked(true); break;  }  foreach(QToolBar* tb, m_toolbars)    tb->setIconSize(QSize(sz, sz));  if(!m_chatCore->lang().isEmpty())  {#if defined(Q_OS_LINUX)  QDir dir(QCoreApplication::applicationDirPath() + "/../share/qchat/translations");#else  QDir dir(QCoreApplication::applicationDirPath() + "/translations");#endif    if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", QChatSettings::settings()->settingsDir()))      if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", dir.path()))        if(!m_translator->load("qchat_" + m_chatCore->lang() + ".qm", "/usr/share/qchat/translations/"))          m_translator->load("qchat_" + m_chatCore->lang() + ".qm", "/usr/local/share/qchat/translations/");    QApplication::installTranslator(m_translator);  }  retranslate();  if(m_chatCore->needCheckIp() == 1)  {    msg = tr("Your network settings don't corresponds any of existing network interfaces.\n"             "The program may not work.\n\n"             "Do you want to configure it now?");    ans = QMessageBox::warning(this,                               tr("Incorrect network settings"),                               msg,                               QMessageBox::Yes | QMessageBox::No);    if(ans == QMessageBox::Yes)      slot_showPreferences();  }  else if(m_chatCore->needCheckIp() == 2)  {    msg = tr("Couldn't find any network interface that can broadcast.\n"             "The program may not work.\n\n"             "Do you want to see your network settings?");    ans = QMessageBox::warning(this,                               tr("No valid network interface!"),                               msg,                               QMessageBox::Yes | QMessageBox::No);    if(ans == QMessageBox::Yes)      slot_showPreferences();  }  setHidePlugins(!m_chatCore->pluginManager()->plugins().size());  if(m_hidePlugins)  {    m_showPluginsTBarAct->setVisible(false);    m_pluginsToolBar->hide();    m_preferencesDlg->hidePluginsSection();  }  m_showPluginsAct->setVisible(false);  m_setServerlessModeAct->trigger();}void ChatWgt::slot_focusChanged(QWidget* old, QWidget* new_){  QChatWidgetPlugin* plug;  m_trayIcon->setStaticIcon(QChatIcon::iconPath("tray-icon"));  if(!mw_smiles || !mw_smiles->inited())    return;  if(new_ && new_ != m_smilesScrllArea)    m_smilesScrllArea->hide();  if(isPLugin(old))  {//     m_pluginsToolBar->clear();    if((plug = isPLugin(new_)))    {//       plug->setupToolBar(m_pluginsToolBar);    }  }}void ChatWgt::slot_processData(QC_DatagramHeader* Hdr){  ChannelWgt* chnnl;  qDebug("[ChatWgt::slot_processData]: chnnl_name = %s\n", QString().fromUtf8(ChatCore::getParametr("Channel", Hdr->parametrs)).toLocal8Bit().data());  qDebug("[ChatWgt::slot_processData]: src_ip = %u\n", (uint)Hdr->src_ip);  // checking if data arrived into private channel  if(Hdr->chnnl_id == 1)  {    // checking is data arrived from us    // in serverless mode we using IP addresses but in Server - UIDs    quint64 uid;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -