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

📄 preferencesdlg.cpp

📁 用qt4 编写的局域网聊天工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************** *   Copyright (C) 2007 by Anistratov Oleg                                 * *   ower@users.sourceforge.net                                            * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License version 2        * *   as published by the Free Software Foundation;                         * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * ***************************************************************************/#include "preferencesdlg.h"#include "globals.h"#include <QSpacerItem>#include <QVBoxLayout>#include <QHBoxLayout>#include <QHostAddress>#include <QStringList>#include <QFile>#include <QCoreApplication>#include "qchatsettings.h"#include "colorlabel.h"#include "pluginsinterfaces.h"#include "pluginmanager.h"#include "plugin.h"#include "userlisticonconfigurewgt.h"#include "iplisteditor.h"#include "chatcore.h"#include "chatwgt.h"#include "messagefiltereditor.h"PreferencesDlg::PreferencesDlg(QWidget *parent) : QDialog(parent){  m_profileName = "";  m_edited      = false;  createWidgets();  QVBoxLayout* btns_box          = new QVBoxLayout(0);  QVBoxLayout* msgs_sect_vbox    = new QVBoxLayout(0);  QGridLayout* grid              = new QGridLayout(this);  QGridLayout* colors_grid       = new QGridLayout(m_colorsGrbx);  QGridLayout* network_grid      = new QGridLayout(m_networkGrbx);  QGridLayout* misc_grid         = new QGridLayout(m_miscGrbx);  QGridLayout* nl_grid           = new QGridLayout(m_nowListeningGrbx);  QGridLayout* smiles_grid       = new QGridLayout(m_smilesThemesGrbx);  QGridLayout* users_list_grid   = new QGridLayout(m_usersListGrbx);  QGridLayout* style_sheets_grid = new QGridLayout(m_styleSheetsGrbx);  QGridLayout* plugins_grid      = new QGridLayout(m_pluginsGrbx);  QGridLayout* iconFormat_grid   = new QGridLayout(m_iconFormatGrbx);  QGridLayout* filtration_grid   = new QGridLayout(m_filtrationGrbx);  QGridLayout* protocols_grid    = new QGridLayout(m_protocolsGrbx);  m_iconFormatWgt = new UserListIconConfigureWgt(this, *QChatSettings::settings()->iconFormat());  connect(m_iconFormatWgt, SIGNAL(formatChanged(UserListIconFormat)), this, SIGNAL(formatChanged(UserListIconFormat)));  // Setting up group boxes  //********************************************  // Colors  m_myColor    ->setMinimumWidth (100); m_myColor    ->setMaximumHeight(25);  m_sysColor   ->setMinimumWidth (100); m_sysColor   ->setMaximumHeight(25);  m_baseColor  ->setMinimumWidth (100); m_baseColor  ->setMaximumHeight(25);  m_myColor    ->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);  m_sysColor   ->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);  m_baseColor  ->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);  colors_grid->addWidget(m_myColorLab          , 0, 0);  colors_grid->addWidget(m_myColor             , 0, 1);  colors_grid->addWidget(m_sysColorLab         , 1, 0);  colors_grid->addWidget(m_sysColor            , 1, 1);  // TODO fully remove baseColor settings  m_baseColorLab->hide();  m_baseColor   ->hide();//   colors_grid->addWidget(m_baseColorLab        , 2, 0);//   colors_grid->addWidget(m_baseColor           , 2, 1);  colors_grid->addWidget(m_colorWholeMsgChbx   , 3, 0, 1, 2);  colors_grid->addWidget(m_colorWholeSysMsgChbx, 4, 0, 1, 2);  colors_grid->setColumnStretch(1, 1);  // Network  m_portOutSpbx->setMaximum(65535);  m_portInSpbx ->setMaximum(65535);  m_applyBtn   ->setEnabled(false);  m_protocolsBgrp->addButton(m_protocolV3Rbtn);  m_protocolsBgrp->addButton(m_protocolV4Rbtn);  protocols_grid->addWidget(m_protocolV3Rbtn);  protocols_grid->addWidget(m_protocolV4Rbtn);  network_grid->addWidget(m_networkIfLab , 0, 0);  network_grid->addWidget(m_networkIfCmbx, 0, 1);  network_grid->addWidget(m_ipLab        , 1, 0);  network_grid->addWidget(m_ipEdit       , 1, 1);  network_grid->addWidget(m_broadcastLab , 2, 0);  network_grid->addWidget(m_broadcastEdit, 2, 1);  network_grid->addWidget(m_portInLab    , 3, 0);  network_grid->addWidget(m_portInSpbx   , 3, 1);  network_grid->addWidget(m_portOutLab   , 4, 0);  network_grid->addWidget(m_portOutSpbx  , 4, 1);  network_grid->addWidget(m_ipListEditor , 5, 0, 1, 2);  network_grid->addWidget(m_useCompressionChbx, 6, 0, 1, 2);  network_grid->addWidget(m_protocolsGrbx, 7, 0, 1, 2);  network_grid->setRowStretch(5, 1);  //Now Listening  nl_grid->addWidget(m_nlInStatusChbx);  nl_grid->addWidget(m_nlWithMessageChbx);  nl_grid->addWidget(m_nlFormatLab);  nl_grid->addWidget(m_nlFormatEdit);  // Misc  misc_grid->addWidget(m_activateOnMsgInChbx, 0, 0);  misc_grid->addWidget(m_isCommandOnIncomingChbx , 1, 0);  misc_grid->addWidget(m_commandOnIncomingEdit, 2, 0);  //Smiles  smiles_grid->addWidget(m_smilesThemeChooser   , 0, 0, 1, 2);  smiles_grid->addWidget(m_smilesPolicyLab      , 1, 0);  smiles_grid->addWidget(m_smilesPolicyCmbx     , 1, 1);  smiles_grid->addWidget(m_useAnimatedSmilesChbx, 2, 0, 1, 2);  // Users List  users_list_grid->addWidget(m_ulRefreshIntervalLab     , 0, 0);  users_list_grid->addWidget(m_ulRefreshIntervalSpbx    , 0, 1);  iconFormat_grid->addWidget(m_iconFormatWgt            , 0, 0);//   users_list_grid->addWidget(m_ulDeepRefreshIntervalLab , 1, 0);//   users_list_grid->addWidget(m_ulDeepRefreshIntervalSpbx, 1, 1);  // Style Sheets  style_sheets_grid->addWidget(m_styleSheetsChooser);  // Plugins  plugins_grid->addWidget(m_pluginsChooser     , 0, 0, 1, 2);  plugins_grid->addWidget(m_loadUnloadPluginBtn, 1, 1);  plugins_grid->setRowStretch(0, 1);  // Filtration  filtration_grid->addWidget(m_messageFilterEditor);  //********************************************  btns_box->addWidget(m_okBtn     );  btns_box->addWidget(m_applyBtn  );  btns_box->addWidget(m_cancelBtn );  msgs_sect_vbox->addWidget(m_colorsGrbx);  msgs_sect_vbox->addWidget(m_miscGrbx);  grid->addWidget(m_sectionsChooser, 0, 0, 2, 1);  grid->addWidget(m_sections       , 0, 1, 2, 2);  grid->addLayout(btns_box         , 0, 3);  grid->setColumnStretch(1, 1);  setupSections();  setupConnections();  retranslate();  resize(400, 200);}//\*****************************************************************************PreferencesDlg::~PreferencesDlg(){  qDebug("[~PreferencesDlg]");}void PreferencesDlg::slot_setMsgColorMode   (int mode){QChatSettings::settings()->setOption("ColorWholeMessage", (mode));}void PreferencesDlg::slot_setSysMsgColorMode(int mode){QChatSettings::settings()->setOption("ColorWholeSystemMessage", (mode));}void PreferencesDlg::slot_setActivateOnMsgIn(int mode){QChatSettings::settings()->setOption("ActivateOnMessageIn", (mode));}void PreferencesDlg::slot_setSoundOnMsgIn   (int mode){QChatSettings::settings()->setOption("SoundOnMessageIn", (mode));}void PreferencesDlg::slot_setNlWithMessage  (int mode){QChatSettings::settings()->setNlMode(m_nlInStatusChbx->isChecked() * 2 | (mode == Qt::Checked));}void PreferencesDlg::slot_setNlInStatus     (int mode){QChatSettings::settings()->setNlMode(m_nlWithMessageChbx->isChecked () | (mode == Qt::Checked) * 2);}void PreferencesDlg::slot_setExecuteCommandMode(int mode){  mode = (mode == Qt::Unchecked ? 0 : 1);  QChatSettings::settings()->setOption("IsExecuteCommandOnIncomingMessage", (mode));  m_commandOnIncomingEdit->setEnabled(mode);}//\*****************************************************************************void PreferencesDlg::init(){  QChatSettings* settings = QChatSettings::settings();  if(!QChatSettings::settings()->boolOption("AllowDifferentPorts"))  {    m_portOutLab ->hide();    m_portOutSpbx->hide();    m_portInLab->setText(tr("Input/Output Port : "));    connect(m_portInSpbx, SIGNAL(valueChanged(int)), m_portOutSpbx, SLOT(setValue(int)));  }  else  {    m_portOutLab ->show();    m_portOutSpbx->show();    m_portInLab->setText(tr("Input Port : "));    disconnect(m_portInSpbx, SIGNAL(valueChanged(int)), m_portOutSpbx, SLOT(setValue(int)));  }  m_myColor  ->setColor(settings->myColor());  m_sysColor ->setColor(settings->sysColor());  m_baseColor->setColor(settings->baseColor());  // CheckBoxes:  if(QChatSettings::settings()->boolOption("ColorWholeMessage"))    m_colorWholeMsgChbx      ->setCheckState(Qt::Checked);  else    m_colorWholeMsgChbx      ->setCheckState(Qt::Unchecked);  if(QChatSettings::settings()->boolOption("ColorWholeSystemMessage"))    m_colorWholeSysMsgChbx   ->setCheckState(Qt::Checked);  else    m_colorWholeSysMsgChbx   ->setCheckState(Qt::Unchecked);  slot_setExecuteCommandMode(settings->boolOption("IsExecuteCommandOnIncomingMessage") ? Qt::Checked : Qt::Unchecked);  m_isCommandOnIncomingChbx->setCheckState(settings->boolOption("IsExecuteCommandOnIncomingMessage") ? Qt::Checked : Qt::Unchecked);  m_useCompressionChbx->setCheckState(QChatSettings::settings()->boolOption("UseCompression") ? Qt::Checked : Qt::Unchecked);  m_useAnimatedSmilesChbx->setCheckState(settings->boolOption("UseAnimatedSmiles") ? Qt::Checked : Qt::Unchecked);  m_smilesPolicyCmbx->setCurrentIndex((int)settings->smilesPolicy());  // NowListening  int mode = settings->nlMode();  if(mode & 1)    m_nlWithMessageChbx->setCheckState(Qt::Checked);  else    m_nlWithMessageChbx->setCheckState(Qt::Unchecked);  if(mode & 2)    m_nlInStatusChbx->setCheckState(Qt::Checked);  else    m_nlInStatusChbx->setCheckState(Qt::Unchecked);  m_nlFormatEdit->setText(settings->strOption("NLFormat"));  m_oldPortIn   = settings->intOption("InputPort");  m_portOutSpbx->setValue(settings->intOption("OutputPort"));  m_portInSpbx ->setValue(m_oldPortIn);  m_ipEdit     ->setText (settings->hostAddressOption("IP").toString());  if(settings->boolOption("ActivateOnMessageIn"))    m_activateOnMsgInChbx   ->setCheckState(Qt::Checked);  else    m_activateOnMsgInChbx   ->setCheckState(Qt::Unchecked);  if(settings->boolOption("SoundOnMessageIn"))    m_soundOnMsgInChbx   ->setCheckState(Qt::Checked);  else    m_soundOnMsgInChbx   ->setCheckState(Qt::Unchecked);  //*************************  m_broadcastEdit->clear();  QString str       = m_ipEdit->text();  QString broadcast = QHostAddress(settings->realBroadcast()).toString();  QStringList list  = str.split(".");  m_broadcastEdit->setText(broadcast);  reloadNetworkIfs();  //*************************  m_commandOnIncomingEdit    ->setText (settings->executeCommandOnIncomingMsg());  m_displayMsgFmtEdit        ->setText (settings->strOption("DisplayMessagesFormat"));  m_msgsHistoryIntervalSpbx  ->setValue(settings->historyReqTimeout());  m_msgsHistoryNumSpbx       ->setValue(settings->nHistoryMsgs());  m_ulRefreshIntervalSpbx    ->setValue(settings->usersListRefreshInterval());  m_ulDeepRefreshIntervalSpbx->setValue(settings->usersListDeepRefreshInterval());  m_commandOnIncomingEdit->home(0);  m_displayMsgFmtEdit->home(0);  m_nlFormatEdit->home(0);  m_profileName = QChatSettings::profileName();  m_edited = false;  m_applyBtn->setEnabled(false);  m_messageFilterEditor->setFilter(settings->messageFilter());  if(settings->intOption("ProtocolVersion") == 3)    m_protocolV3Rbtn->setChecked(true);  else if(settings->intOption("ProtocolVersion") == 4)    m_protocolV4Rbtn->setChecked(true);  if(settings->mode() == QChatSettings::Server)  {    m_protocolV4Rbtn->setEnabled(false);    m_protocolV3Rbtn->setEnabled(false);    m_protocolV4Rbtn->setChecked(true);  }  else  {    m_protocolV4Rbtn->setEnabled(true);    m_protocolV3Rbtn->setEnabled(true);  }  setWindowTitle(tr("Preferences [Profile: ") + m_profileName + "]");}//\*****************************************************************************void PreferencesDlg::slot_chooseColor(){  QColor color = QColorDialog::getColor(((ColorLabel*)sender())->color(), this);  if(color.isValid())  {    ((ColorLabel*)sender())->setColor(color);    edited();  }}//\*****************************************************************************void PreferencesDlg::edited(){  m_edited = true;  m_applyBtn->setEnabled(true);}//\*****************************************************************************void PreferencesDlg::slot_setPrefs(){  int idx;  if(QChatSettings::profileName() == m_profileName)  {    switch(Sections(m_sectionsChooser->currentRow()))    {      case Network :        break;      case Messages :        break;

⌨️ 快捷键说明

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