mainwindow.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 962 行 · 第 1/3 页
CPP
962 行
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the tools applications of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "mainwindow.h"#include "colorbutton.h"#include "previewframe.h"#include "paletteeditoradvanced.h"#include <QLabel>#include <QApplication>#include <QComboBox>#include <QStyleFactory>#include <QFontDatabase>#include <QLineEdit>#include <QSpinBox>#include <QCheckBox>#include <QFileDialog>#include <QAction>#include <QStatusBar>#include <QSettings>#include <QMessageBox>#include <QStyle>#include <QtEvents>#include <Q3ValueList>#include <QtDebug>#include <stdlib.h>// from qapplication.cpp and qapplication_x11.cpp - These are NOT for// external use ignore them// extern bool Q_CORE_EXPORT qt_resolve_symlinks;static const char *appearance_text ="<p><b><font size+=2>Appearance</font></b></p>""<hr>""<p>Use this tab to customize the appearance of your Qt applications.</p>""<p>You can select the default GUI Style from the drop down list and ""customize the colors.</p>""<p>Any GUI Style plugins in your plugin path will automatically be added ""to the list of built-in Qt styles. (See the Library Paths tab for ""information on adding new plugin paths.)</p>""<p>When you choose 3-D Effects and Window Background colors, the Qt ""Configuration program will automatically generate a palette for you. ""To customize colors further, press the Tune Palette button to open ""the advanced palette editor.""<p>The Preview Window shows what the selected Style and colors look ""like.";static const char *font_text ="<p><b><font size+=2>Fonts</font></b></p>""<hr>""<p>Use this tab to select the default font for your Qt applications. ""The selected font is shown (initially as 'Sample Text') in the line ""edit below the Family, ""Style and Point Size drop down lists.</p>""<p>Qt has a powerful font substitution feature that allows you to ""specify a list of substitute fonts. Substitute fonts are used ""when a font cannot be loaded, or if the specified font doesn't have ""a particular character.""<p>For example, if you select the font Lucida, which doesn't have Korean ""characters, but need to show some Korean text using the Mincho font family ""you can do so by adding Mincho to the list. Once Mincho is added, any ""Korean characters that are not found in the Lucida font will be taken ""from the Mincho font. Because the font substitutions are ""lists, you can also select multiple families, such as Song Ti (for ""use with Chinese text).";static const char *interface_text ="<p><b><font size+=2>Interface</font></b></p>""<hr>""<p>Use this tab to customize the feel of your Qt applications.</p>""<p>If the Resolve Symlinks checkbox is checked Qt will follow symlinks ""when handling URLs. For example, in the file dialog, if this setting is turned ""on and /usr/tmp is a symlink to /var/tmp, entering the /usr/tmp directory ""will cause the file dialog to change to /var/tmp. With this setting turned ""off, symlinks are not resolved or followed.</p>""<p>The Global Strut setting is useful for people who require a ""minimum size for all widgets (e.g. when using a touch panel or for users ""who are visually impaired). Leaving the Global Strut width and height ""at 0 will disable the Global Strut feature</p>""<p>XIM (Extended Input Methods) are used for entering characters in ""languages that have large character sets, for example, Chinese and ""Japanese.";// ### What does the 'Enhanced support for languages written R2L do?static const char *printer_text ="<p><b><font size+=2>Printer</font></b></p>""<hr>""<p>Use this tab to configure the way Qt generates output for the printer.""You can specify if Qt should try to embed fonts into its generated output.""If you enable font embedding, the resulting postscript will be more ""portable and will more accurately reflect the ""visual output on the screen; however the resulting postscript file ""size will be bigger.""<p>When using font embedding you can select additional directories where ""Qt should search for embeddable font files. By default, the X ""server font path is used.";static QColorGroup::ColorRole centralFromItem( int item ){ switch( item ) { case 0: return QColorGroup::Window; case 1: return QColorGroup::WindowText; case 2: return QColorGroup::Button; case 3: return QColorGroup::Base; case 4: return QColorGroup::Text; case 5: return QColorGroup::BrightText; case 6: return QColorGroup::ButtonText; case 7: return QColorGroup::Highlight; case 8: return QColorGroup::HighlightedText; default: return QColorGroup::NColorRoles; }}static QColorGroup::ColorRole effectFromItem( int item ){ switch( item ) { case 0: return QColorGroup::Light; case 1: return QColorGroup::Midlight; case 2: return QColorGroup::Mid; case 3: return QColorGroup::Dark; case 4: return QColorGroup::Shadow; default: return QColorGroup::NColorRoles; }}static void setStyleHelper(QWidget *w, QStyle *s){ const QObjectList children = w->children(); for (int i = 0; i < children.size(); ++i) { QObject *child = children.at(i); if (child->isWidgetType()) setStyleHelper((QWidget *) child, s); } w->setStyle(s);}MainWindow::MainWindow() : MainWindowBase(0, "main window"), editPalette(palette()), previewPalette(palette()), previewstyle(0){ modified = true; QStringList gstyles = QStyleFactory::keys(); gstyles.sort(); gstylecombo->insertStringList(gstyles); QSettings settings(QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("Qt")); QString currentstyle = settings.value(QLatin1String("style")).toString(); if (currentstyle.isNull()) currentstyle = QLatin1String(QApplication::style()->name()); { int s = 0; QStringList::Iterator git = gstyles.begin(); while (git != gstyles.end()) { if ((*git).lower() == currentstyle.lower()) break; s++; git++; } if (s < gstylecombo->count()) { gstylecombo->setCurrentItem(s); } else { // no predefined style, try to find the closest match // class names usually contain the name of the style, so we // iterate over the items in the combobox, and use the one whose // name is contained in the classname of the style s = 0; git = gstyles.begin(); while (git != gstyles.end()) { if (currentstyle.contains(*git)) break; s++; git++; } if (s < gstylecombo->count()) { gstylecombo->setCurrentItem(s); } else { // we give up gstylecombo->insertItem(QLatin1String("Unknown")); gstylecombo->setCurrentItem(gstylecombo->count() - 1); } } } buttonMainColor->setColor(palette().color(QPalette::Active, QColorGroup::Button)); buttonMainColor2->setColor(palette().color(QPalette::Active, QColorGroup::Window)); connect(buttonMainColor, SIGNAL(colorChanged(QColor)), this, SLOT(buildPalette())); connect(buttonMainColor2, SIGNAL(colorChanged(QColor)), this, SLOT(buildPalette())); QFontDatabase db; QStringList families = db.families(); familycombo->insertStringList(families); QStringList fs = families; QStringList fs2 = QFont::substitutions(); QStringList::Iterator fsit = fs2.begin(); while (fsit != fs2.end()) { if (! fs.contains(*fsit)) fs += *fsit; fsit++; } fs.sort(); familysubcombo->insertStringList(fs); choosesubcombo->insertStringList(families); Q3ValueList<int> sizes = db.standardSizes(); Q3ValueList<int>::Iterator it = sizes.begin(); while (it != sizes.end()) psizecombo->insertItem(QString::number(*it++)); dcispin->setValue(QApplication::doubleClickInterval()); cfispin->setValue(QApplication::cursorFlashTime()); wslspin->setValue(QApplication::wheelScrollLines()); // #############// resolvelinks->setChecked(qt_resolve_symlinks); effectcheckbox->setChecked(QApplication::isEffectEnabled(Qt::UI_General)); effectbase->setEnabled(effectcheckbox->isChecked()); if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) menueffect->setCurrentItem(2); else if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) menueffect->setCurrentItem(1); if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)) comboeffect->setCurrentItem(1); if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip)) tooltipeffect->setCurrentItem(2); else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip)) tooltipeffect->setCurrentItem(1); if ( QApplication::isEffectEnabled( Qt::UI_AnimateToolBox ) ) toolboxeffect->setCurrentItem( 1 ); QSize globalStrut = QApplication::globalStrut(); strutwidth->setValue(globalStrut.width()); strutheight->setValue(globalStrut.height()); // find the default family QStringList::Iterator sit = families.begin(); int i = 0, possible = -1; while (sit != families.end()) { if (*sit == QApplication::font().family()) break; if ((*sit).contains(QApplication::font().family())) possible = i; i++; sit++; } if (sit == families.end()) i = possible; if (i == -1) // no clue about the current font i = 0; familycombo->setCurrentItem(i); QStringList styles = db.styles(familycombo->currentText()); stylecombo->insertStringList(styles); QString stylestring = db.styleString(QApplication::font()); sit = styles.begin(); i = 0; possible = -1; while (sit != styles.end()) { if (*sit == stylestring) break; if ((*sit).contains(stylestring)) possible = i; i++; sit++; } if (sit == styles.end())
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?