tabbedbrowser.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 526 行 · 第 1/2 页

CPP
526
字号
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Assistant 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 "tabbedbrowser.h"#include "mainwindow.h"#include "helpwindow.h"#include "config.h"#include <QStyleOptionTab>#include <QToolTip>#include <QFileInfo>#include <QToolButton>#include <QPixmap>#include <QIcon>#include <QStyle>#include <QTimer>#include <QStackedWidget>#include <QTimer>#include <QTextBlock>#include <QKeyEvent>#ifdef Q_WS_MACconst QLatin1String ImageLocation(":trolltech/assistant/images/mac/");#elseconst QLatin1String ImageLocation(":trolltech/assistant/images/win/");#endifTabbedBrowser::TabbedBrowser(MainWindow *parent)    : QWidget(parent){    ui.setupUi(this);    init();    QStackedWidget *stack = qFindChild<QStackedWidget*>(ui.tab);    Q_ASSERT(stack);    stack->setContentsMargins(0, 0, 0, 0);    connect(stack, SIGNAL(currentChanged(int)), parent, SLOT(browserTabChanged()));    QPalette p = palette();    p.setColor(QPalette::Inactive, QPalette::Highlight,        p.color(QPalette::Active, QPalette::Highlight));    p.setColor(QPalette::Inactive, QPalette::HighlightedText,        p.color(QPalette::Active, QPalette::HighlightedText));    setPalette(p);}TabbedBrowser::~TabbedBrowser(){}MainWindow *TabbedBrowser::mainWindow() const{    return static_cast<MainWindow*>(parentWidget());}void TabbedBrowser::forward(){    currentBrowser()->forward();    emit browserUrlChanged(currentBrowser()->source().toString());}void TabbedBrowser::backward(){    currentBrowser()->backward();    emit browserUrlChanged(currentBrowser()->source().toString());}void TabbedBrowser::setSource( const QString &ref ){    HelpWindow * win = currentBrowser();    win->setSource(ref);}void TabbedBrowser::reload(){    currentBrowser()->reload();}void TabbedBrowser::home(){    currentBrowser()->home();}HelpWindow *TabbedBrowser::currentBrowser() const{    return static_cast<HelpWindow*>(ui.tab->currentWidget());}void TabbedBrowser::nextTab(){    if(ui.tab->currentIndex()<=ui.tab->count()-1)        ui.tab->setCurrentIndex(ui.tab->currentIndex()+1);}void TabbedBrowser::previousTab(){    int idx = ui.tab->currentIndex()-1;    if(idx>=0)        ui.tab->setCurrentIndex(idx);}HelpWindow *TabbedBrowser::createHelpWindow(){    MainWindow *mainWin = mainWindow();    HelpWindow *win = new HelpWindow(mainWin, 0);    win->setFrameStyle(QFrame::NoFrame);    win->setPalette(palette());    win->setSearchPaths(Config::configuration()->mimePaths());    ui.tab->addTab(win, tr("..."));    connect(win, SIGNAL(highlighted(QString)),             (const QObject*) (mainWin->statusBar()), SLOT(showMessage(QString)));    connect(win, SIGNAL(backwardAvailable(bool)),             mainWin, SLOT(backwardAvailable(bool)));    connect(win, SIGNAL(forwardAvailable(bool)),             mainWin, SLOT(forwardAvailable(bool)));    connect(win, SIGNAL(sourceChanged(QUrl)), this, SLOT(sourceChanged()));    ui.tab->cornerWidget(Qt::TopRightCorner)->setEnabled(ui.tab->count() > 1);	win->installEventFilter(this);	win->viewport()->installEventFilter(this);    ui.editFind->installEventFilter(this);    return win;}HelpWindow *TabbedBrowser::newBackgroundTab(){    HelpWindow *win = createHelpWindow();    emit tabCountChanged(ui.tab->count());    return win;}void TabbedBrowser::newTab(const QString &lnk){    QString link(lnk);    if(link.isNull()) {        HelpWindow *w = currentBrowser();        if(w)            link = w->source().toString();    }    HelpWindow *win = createHelpWindow();    ui.tab->setCurrentIndex(ui.tab->indexOf(win));    if(!link.isNull()) {         win->setSource(link);    }    emit tabCountChanged(ui.tab->count());}void TabbedBrowser::zoomIn(){    currentBrowser()->zoomIn();    Config::configuration()->setFontPointSize(currentBrowser()->font().pointSizeF());}void TabbedBrowser::zoomOut(){    currentBrowser()->zoomOut();    Config::configuration()->setFontPointSize(currentBrowser()->font().pointSizeF());}void TabbedBrowser::init(){    lastCurrentTab = 0;    while(ui.tab->count()) {        QWidget *page = ui.tab->widget(0);        ui.tab->removeTab(0);        delete page;    }    connect(ui.tab, SIGNAL(currentChanged(int)),             this, SLOT(transferFocus()));    QTabBar *tabBar = qFindChild<QTabBar*>(ui.tab);    QStyleOptionTab opt;    if (tabBar) {        opt.init(tabBar);        opt.shape = tabBar->shape();        tabBar->setContextMenuPolicy(Qt::CustomContextMenu);        connect(tabBar, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(openTabMenu(const QPoint&)));    }    // workaround for sgi style    QPalette pal = palette();    pal.setColor(QPalette::Active, QPalette::Button, pal.color(QPalette::Active, QPalette::Window));    pal.setColor(QPalette::Disabled, QPalette::Button, pal.color(QPalette::Disabled, QPalette::Window));    pal.setColor(QPalette::Inactive, QPalette::Button, pal.color(QPalette::Inactive, QPalette::Window));    QToolButton *newTabButton = new QToolButton(this);    ui.tab->setCornerWidget(newTabButton, Qt::TopLeftCorner);    newTabButton->setCursor(Qt::ArrowCursor);    newTabButton->setAutoRaise(true);    newTabButton->setIcon(QIcon(ImageLocation + QLatin1String("addtab.png")));    QObject::connect(newTabButton, SIGNAL(clicked()), this, SLOT(newTab()));    newTabButton->setToolTip(tr("Add page"));    QToolButton *closeTabButton = new QToolButton(this);    closeTabButton->setPalette(pal);    ui.tab->setCornerWidget(closeTabButton, Qt::TopRightCorner);    closeTabButton->setCursor(Qt::ArrowCursor);    closeTabButton->setAutoRaise(true);    closeTabButton->setIcon(QIcon(ImageLocation + QLatin1String("closetab.png")));    QObject::connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeTab()));    closeTabButton->setToolTip(tr("Close page"));    closeTabButton->setEnabled(false);	QObject::connect(ui.toolClose, SIGNAL(clicked()), ui.frameFind, SLOT(hide()));	QObject::connect(ui.toolPrevious, SIGNAL(clicked()), this, SLOT(findPrevious()));	QObject::connect(ui.toolNext, SIGNAL(clicked()), this, SLOT(findNext()));	QObject::connect(ui.editFind, SIGNAL(returnPressed()), this, SLOT(findNext()));	QObject::connect(ui.editFind, SIGNAL(textEdited(const QString&)),				     this, SLOT(find(QString)));	ui.frameFind->setVisible(false);	ui.labelWrapped->setVisible(false);	autoHideTimer = new QTimer(this);	autoHideTimer->setInterval(5000);	autoHideTimer->setSingleShot(true);	QObject::connect(autoHideTimer, SIGNAL(timeout()), ui.frameFind, SLOT(hide()));}void TabbedBrowser::updateTitle(const QString &title){    ui.tab->setTabText(ui.tab->indexOf(currentBrowser()), title.trimmed());}void TabbedBrowser::newTab(){    newTab(QString());}

⌨️ 快捷键说明

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