📄 preferences.cpp
字号:
/** preferences.cpp*/#include "preferences.h"#include "mainwindow.h"#include "qgo.h"#include "mainwin.h"#include <qlistbox.h>#include <qcheckbox.h>#include <qwhatsthis.h>#include <qcombobox.h>#include <qlineedit.h>#include <qfontdialog.h>#include <qcolordialog.h>#include <qcolor.h>#include <qpalette.h>#include <qlabel.h>#include <qpushbutton.h>#include <qtextcodec.h>#include <stdlib.h>#include <time.h>#include <qvalidator.h>#include <qlistview.h>#include <qbuttongroup.h>#include <qtooltip.h> #include <qtoolbutton.h>#include <qobjectlist.h>#include <qspinbox.h>#ifdef Q_OS_MACX#include <CoreFoundation/CFString.h>#include <CoreFoundation/CFBundle.h>#endif //Q_OS_MACX/* * Constructs a PreferencesDialog which is a child of 'parent', with the * name 'name' and widget flags set to 'f' ** The dialog will by default be modeless, unless you set 'modal' to* TRUE to construct a modal dialog.*/PreferencesDialog::PreferencesDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : PreferencesDialogGui( parent, name, modal, fl ){ ListView_buttons->setColumnWidth(4,0); // pointer to ClientWindow parent_cw = setting->cw; CHECK_PTR(parent_cw); if (parent_cw->getPrefSize().width() > 0) { resize(parent_cw->getPrefSize()); move(parent_cw->getPrefPos()); } // set hostlist //parent_cw->hostlist; // set connection titles to listview for (Host *h = parent_cw->hostlist.first(); h != 0; h = parent_cw->hostlist.next()) new QListViewItem(ListView_hosts, h->title(), h->host(), QString::number(h->port()), h->loginName(), (h->password().length() ? "***" : "")); //cb_title->insertItem(h->title()); // set the user toolbar list QPixmap p; QToolButton *b0 ; QListViewItem *lvi; QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false); for ( b0 = (QToolButton*)bl->first(); b0 != 0; b0 = (QToolButton*)bl->next()) { lvi = new QListViewItem(ListView_buttons, "", //first column is for pixmap b0->textLabel(), b0->caption(), QToolTip::textFor (b0), b0->iconText() ); if (p.load(b0->iconText())) lvi->setPixmap(0,p); } // init random-number generator srand( (unsigned)time( NULL ) ); insertStandardHosts(); // set valid port range val = new QIntValidator(0, 9999, this); LineEdit_port->setValidator(val); // clear edit field LineEdit_title->clear(); fontStandardButton->setText(setting->fontToString(setting->fontStandard)); fontMarksButton->setText(setting->fontToString(setting->fontMarks)); fontCommentsButton->setText(setting->fontToString(setting->fontComments)); fontListsButton->setText(setting->fontToString(setting->fontLists)); fontClocksButton->setText(setting->fontToString(setting->fontClocks)); fontConsoleButton->setText(setting->fontToString(setting->fontConsole)); fontStandardButton->setFont(setting->fontStandard); fontMarksButton->setFont(setting->fontMarks); fontCommentsButton->setFont(setting->fontComments); fontListsButton->setFont(setting->fontLists); fontClocksButton->setFont(setting->fontClocks); fontConsoleButton->setFont(setting->fontConsole); QPalette pal = colorBackgroundButton->palette(); pal.setColor(QColorGroup::Button, setting->colorBackground); colorBackgroundButton->setPalette(pal); pal = colorAltBackgroundButton->palette(); pal.setColor(QColorGroup::Button, setting->colorAltBackground); colorAltBackgroundButton->setPalette(pal);#ifdef QGO_NOSTYLES styleListBox->setDisabled(true);#endif // Default codec ComboBox_codec->insertItem(""); // The rest by name QTextCodec *codec; for(int i = 0; (codec = QTextCodec::codecForIndex(i)); ++i) ComboBox_codec->insertItem(codec->name());}/* * Destroys the object and frees any allocated resources*/PreferencesDialog::~PreferencesDialog(){ // no need to delete child widgets, Qt does it all for us}/******************************************************************* Overwritten own implementations******************************************************************/void PreferencesDialog::slot_apply(){ ((MainWindow*)parentWidget())->preferencesSave(this); ((MainWindow*)parentWidget())->preferencesAccept();}void PreferencesDialog::startHelpMode(){ QWhatsThis::enterWhatsThisMode();}void PreferencesDialog::selectFont(int selector){ // Open a font dialog to select a new font bool ok; QFont f; switch (selector) { case 0: f = QFontDialog::getFont(&ok, setting->fontStandard, this); if (ok) // Accepted { setting->fontStandard = f; fontStandardButton->setText(setting->fontToString(f)); fontStandardButton->setFont(f); } break; case 1: f = QFontDialog::getFont(&ok, setting->fontMarks, this); if (ok) // Accepted { setting->fontMarks = f; fontMarksButton->setText(setting->fontToString(f)); fontMarksButton->setFont(f); } break; case 2: f = QFontDialog::getFont(&ok, setting->fontComments, this); if (ok) // Accepted { setting->fontComments = f; fontCommentsButton->setText(setting->fontToString(f)); fontCommentsButton->setFont(f); } break; case 3: f = QFontDialog::getFont(&ok, setting->fontLists, this); if (ok) // Accepted { setting->fontLists = f; fontListsButton->setText(setting->fontToString(f)); fontListsButton->setFont(f); } break; case 4: f = QFontDialog::getFont(&ok, setting->fontClocks, this); if (ok) // Accepted { setting->fontClocks = f; fontClocksButton->setText(setting->fontToString(f)); fontClocksButton->setFont(f); } break; case 5: f = QFontDialog::getFont(&ok, setting->fontConsole, this); if (ok) // Accepted { setting->fontConsole = f; fontConsoleButton->setText(setting->fontToString(f)); fontConsoleButton->setFont(f); } break; default: break; }}void PreferencesDialog::selectColor(){ // Open a font dialog to select a new font QColor c = QColorDialog::getColor(setting->colorBackground, this); if (c.isValid()) // Accepted { setting->colorBackground = c; // set button color QPalette pal = colorBackgroundButton->palette(); pal.setColor(QColorGroup::Button, setting->colorBackground); colorBackgroundButton->setPalette(pal); }}void PreferencesDialog::selectAltColor(){ // Open a font dialog to select a new font QColor c = QColorDialog::getColor(setting->colorAltBackground, this); if (c.isValid()) // Accepted { setting->colorAltBackground = c; // set button color QPalette pal = colorAltBackgroundButton->palette(); pal.setColor(QColorGroup::Button, setting->colorAltBackground); colorAltBackgroundButton->setPalette(pal); }}void PreferencesDialog::slot_accept(){ saveSizes(); // save settings parent_cw->saveSettings(); accept();}void PreferencesDialog::slot_reject(){ saveSizes(); reject();}void PreferencesDialog::saveSizes(){ // save size and position of window parent_cw->savePrefFrame(pos(), size()); // update hosts parent_cw->slot_cbconnect(QString());}void PreferencesDialog::insertStandardHosts(){ // standard hosts new QListViewItem(ListView_hosts, "-- Aurora --"); new QListViewItem(ListView_hosts, "-- CTN --"); new QListViewItem(ListView_hosts, "-- CWS --"); new QListViewItem(ListView_hosts, "-- EGF --"); new QListViewItem(ListView_hosts, "-- IGS --"); new QListViewItem(ListView_hosts, "-- LGS --"); new QListViewItem(ListView_hosts, "-- NNGS --"); new QListViewItem(ListView_hosts, "-- WING --");}// button "add" clicked or "ok" pressedvoid PreferencesDialog::slot_add(){ // check if at least title and host inserted if (!LineEdit_title->text().isEmpty() && !LineEdit_host->text().isEmpty()) { // check if title already exists bool found = false; bool check; unsigned int tmp = LineEdit_port->text().toUInt(&check); if (!check) { tmp = 0; qWarning("Failed to convert port to integer!"); } for (Host *h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next()) { if (h->title() == LineEdit_title->text()) { found = true; // if found, insert at current pos, and remove old item parent_cw->hostlist.remove(); } } // insert host at it's sorted position parent_cw->hostlist.inSort(new Host(LineEdit_title->text(), LineEdit_host->text(), tmp, LineEdit_login->text(), LineEdit_pass->text(), ComboBox_codec->currentText())); // create entry in listview if (!found) new QListViewItem(ListView_hosts, LineEdit_title->text(), LineEdit_host->text(), QString::number(tmp), LineEdit_login->text(), (LineEdit_pass->text().length() ? "***" : "")); else { ListView_hosts->currentItem()->setText(0, LineEdit_title->text()); ListView_hosts->currentItem()->setText(1, LineEdit_host->text()); ListView_hosts->currentItem()->setText(2, QString::number(tmp)); ListView_hosts->currentItem()->setText(3, LineEdit_login->text()); ListView_hosts->currentItem()->setText(4, (LineEdit_pass->text().length() ? "***" : "")); } ListView_hosts->repaint();// cb_title->insertItem(LineEdit_title->text(), 0); // add to ClientWindow hostlist !!! does not seem to be used ! emit signal_addHost(LineEdit_title->text(), LineEdit_host->text(), tmp, LineEdit_login->text(), LineEdit_pass->text()); } // init insertion fields slot_cbtitle(QString());}// button "delete" clickedvoid PreferencesDialog::slot_delete(){ bool found = false; Host *h; for (h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next()) { if (h->title() == LineEdit_title->text()) { found = true; // if found, delete current entry parent_cw->hostlist.remove(); emit signal_delHost(LineEdit_title->text()); } } // set connection titles to listview QListViewItemIterator lv(ListView_hosts); for (QListViewItem *lvi; (lvi = lv.current());) { lv++; delete lvi; } // clear entries
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -