📄 preferencesdlg.cpp
字号:
list.append(m_nowListeningGrbx);#else m_nowListeningGrbx->hide();#endif list.append(m_usersListGrbx); list.append(m_iconFormatGrbx); m_sections->insertWidget(Misc, setupSectionLayout(list)); // StylesSheets connect(m_styleSheetsChooser, SIGNAL(currentRowChanged(int)), this, SLOT(edited())); m_sections->insertWidget(StyleSheets, m_styleSheetsGrbx); // Plugins m_sections->insertWidget(Plugins, m_pluginsGrbx); connect(m_pluginsChooser, SIGNAL(currentRowChanged(int)), this, SLOT(updatePluginButtons(int))); m_ulDeepRefreshIntervalSpbx->hide(); m_ulDeepRefreshIntervalLab->hide();}QWidget* PreferencesDlg::setupSectionLayout(QList<QWidget*> list){ QWidget* wgt = new QWidget(0); QVBoxLayout* vbox = new QVBoxLayout(wgt); int i; vbox->setMargin(0); for(i = 0; i < list.size(); i++) vbox->addWidget(list[i]); vbox->addStretch(); return wgt;}QWidget* PreferencesDlg::setupSectionLayout(QWidget* w, bool add_stretch){ QWidget* wgt = new QWidget(0); QGridLayout* grid = new QGridLayout(wgt); grid->setMargin(0); grid->addWidget(w, 0, 0); if(add_stretch) grid->setRowStretch(1, 1); return wgt;}void PreferencesDlg::slot_activateSection(int idx){ int idx_; int edited = m_edited; switch(idx) { case Network : reloadNetworkIfs(); m_ipListEditor->init(); break; case Messages : break; case Filtration : m_messageFilterEditor->refresh(); break; case Smiles : reloadSmileThemeList(); if((idx_ = m_smilesThemes.indexOf(QChatSettings::settings()->smilesThemePath())) >= 0) m_smilesThemeChooser->setCurrentRow(idx_); m_edited = edited; m_applyBtn->setEnabled(edited); break; case Misc : break; case StyleSheets : reloadStyleSheetsList(); m_edited = edited; m_applyBtn->setEnabled(edited); break; case Plugins : reloadPluginsList(); break; } m_sections->setCurrentIndex(idx);}void PreferencesDlg::reloadSmileThemeList(){ QDir dir(QChatSettings::settings()->settingsDir() + "/smiles"); m_smilesThemes.clear(); m_smilesThemeChooser->clear(); emoticonsThemesFromDir(dir);#if defined(Q_OS_LINUX) dir.setPath(QDir::homePath() + "/.kde/share/emoticons"); emoticonsThemesFromDir(dir);#endif#if defined(Q_OS_LINUX) dir.setPath(QCoreApplication::applicationDirPath()); if(dir.cd("../share/emoticons")) emoticonsThemesFromDir(dir); if(dir.path() != "/usr/share/emoticons" && dir.cd("/usr/share/emoticons")) emoticonsThemesFromDir(dir);#else dir.setPath(QCoreApplication::applicationDirPath() + "/emoticons"); emoticonsThemesFromDir(dir);#endif}void PreferencesDlg::reloadStyleSheetsList(){ QDir dir(QChatSettings::settings()->settingsDir() + "/stylesheets"); QFile file; QStringList list; bool ok = 1; m_styleSheets.clear(); m_styleSheetsChooser->clear(); list = dir.entryList(); for(int i = 0; i < list.size(); i++) { if(list[i] == "." || list[i] == ".." || !QFileInfo(dir.absolutePath() + "/" + list[i]).isFile()) continue; m_styleSheetsChooser->addItem(list[i]); m_styleSheets.append(dir.absolutePath() + "/" + list[i]); }#if defined(Q_OS_LINUX) dir.setPath(QCoreApplication::applicationDirPath()); ok = dir.cd("../share/qchat/stylesheets");#else dir.setPath(QCoreApplication::applicationDirPath() + "/stylesheets");#endif if(ok) { list = dir.entryList(); for(int i = 0; i < list.size(); i++) { if(list[i] == "." || list[i] == ".." || !QFileInfo(dir.absolutePath() + "/" + list[i]).isFile()) continue; m_styleSheetsChooser->addItem(list[i]); m_styleSheets.append(dir.absolutePath() + "/" + list[i]); } }}void PreferencesDlg::emoticonsThemesFromDir(QDir dir){ QFile file; if(dir.exists()) foreach(QString em_dir, dir.entryList()) { if(em_dir == "." || em_dir == ".." || QFileInfo(dir.absolutePath() + "/" + em_dir).isFile() || !QFile(dir.absolutePath() + "/" + em_dir + "/emoticons.xml").exists()) continue; m_smilesThemeChooser->addItem(em_dir); m_smilesThemes.append(dir.absolutePath() + "/" + em_dir + "/"); }}void PreferencesDlg::reloadNetworkIfs(){ QList<QNetworkInterface> all_i = QNetworkInterface::allInterfaces(); m_networkIfCmbx->clear(); m_networkIfCmbx->addItem(tr("Custom (not recommended)")); m_addressEntries.clear(); foreach(QNetworkInterface i, all_i) foreach(QNetworkAddressEntry e, i.addressEntries()) { if(e.broadcast().isNull()) continue; m_addressEntries.append(e); m_networkIfCmbx->addItem(i.name()); } for(int i = 0; i < m_addressEntries.size(); i++) if((m_addressEntries[i].ip() == QHostAddress(QChatSettings::settings()->hostAddressOption("IP"))) && (m_addressEntries[i].broadcast() == QChatSettings::settings()->realBroadcast())) { m_networkIfCmbx->setCurrentIndex(i + 1); m_ipEdit ->setEnabled(false); m_broadcastEdit->setEnabled(false); }}void PreferencesDlg::setNetworkIf(int idx){ m_ipEdit ->setEnabled(!idx); m_broadcastEdit->setEnabled(!idx); if(!idx) { m_broadcastEdit->setText(QChatSettings::settings()->hostAddressOption("CustomBroadcast").toString()); m_ipEdit ->setText(QChatSettings::settings()->hostAddressOption("CustomIP").toString()); } else { QNetworkAddressEntry e = m_addressEntries[idx - 1]; m_broadcastEdit->setText(e.broadcast().toString()); m_ipEdit->setText(e.ip().toString()); }}int PreferencesDlg::addSection(QWidget* section, const QString & name){ if(section) { m_sectionsChooser->addItem(name); m_sections ->addWidget(section); return m_sectionsChooser->count() - 1; } return 0;}void PreferencesDlg::setupPluginsSection(QList< QObject * > plugins){ QChatBasicPlugin* plugin; m_pluginsChooser->clear(); foreach(QObject* obj, plugins) { plugin = qobject_cast<QChatWidgetPlugin*>(obj); if(plugin) m_pluginsChooser->addItem(plugin->name()); }}void PreferencesDlg::setIconFormat(const UserListIconFormat & fmt){ m_iconFormatWgt->setFormat(fmt);}void PreferencesDlg::removeSection(QWidget* section){ int idx; if(section) { if((idx = m_sections->indexOf(section)) >= 0/*LastSection*/) { m_sections->removeWidget(section); delete m_sectionsChooser->takeItem(idx); } }}void PreferencesDlg::reloadPluginsList(){ ChatWgt* wgt = qobject_cast<ChatWgt*>(parentWidget()); QListWidgetItem* item; if(wgt) { m_pluginsChooser->clear(); foreach(Plugin* pl, wgt->core()->pluginManager()->plugins()) { item = new QListWidgetItem(pl->name() + (pl->isLoaded() ? tr(" (Loaded)") : tr(" (Not loaded)")), m_pluginsChooser); item->setData(Qt::UserRole, pl->path()); item->setData(Qt::UserRole + 1, pl->isLoaded()); m_pluginsChooser->addItem(item); } }}void PreferencesDlg::updatePluginButtons(int row){ if(row >= 0) { bool loaded = false; QListWidgetItem* item = m_pluginsChooser->currentItem(); if(item) loaded = item->data(Qt::UserRole + 1).toBool(); m_loadUnloadPluginBtn->setText(loaded ? tr("Unload plugin") : tr("Load plugin")); m_loadUnloadPluginBtn->setEnabled(true); } else m_loadUnloadPluginBtn->setEnabled(false);}void PreferencesDlg::loadOrUnloadPlugin(){ QListWidgetItem* item = m_pluginsChooser->currentItem(); QString path; bool loaded; if(item) { path = item->data(Qt::UserRole).toString(); loaded = item->data(Qt::UserRole + 1).toBool(); if(loaded) emit wantUnloadPlugin(path); else emit wantLoadPlugin(path); m_loadUnloadPluginBtn->setText(loaded ? tr("Unload plugin") : tr("Load plugin")); reloadPluginsList(); }}void PreferencesDlg::hidePluginsSection(){ m_sectionsChooser->takeItem(Plugins); m_sections->removeWidget(m_pluginsGrbx);}void PreferencesDlg::setUseCompression(int state){ QChatSettings::settings()->setOption("UseCompression", (state == Qt::Checked));}void PreferencesDlg::protocolChanged(){ if(sender() == m_protocolV3Rbtn) { m_useCompressionChbx->setEnabled(false); emit wantChangeProtocol(3); } else if(sender() == m_protocolV4Rbtn) { m_useCompressionChbx->setEnabled(true); emit wantChangeProtocol(4); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -