htmlview.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 313 行 · 第 1/2 页

CPP
313
字号
// (c) 2005 Christian Muehlhaeuser <chris@chris.de>// (c) 2006 Seb Ruiz <me@sebruiz.net>// License: GNU General Public License V2#include "amarok.h"#include "amarokconfig.h"#include "app.h"#include "contextbrowser.h"#include "htmlview.h"#include "playlist.h"      //appendMedia()#include <qclipboard.h>#include <qfile.h> // External CSS opening#include <qimage.h> // External CSS opening#include <kapplication.h> //kapp#include <kactioncollection.h>#include <kglobal.h> //kapp#include <kimageeffect.h> // gradient background image#include <kpopupmenu.h>#include <kstandarddirs.h> //locate file#include <ktempfile.h>KTempFile *HTMLView::m_bgGradientImage = 0;KTempFile *HTMLView::m_headerGradientImage = 0;KTempFile *HTMLView::m_shadowGradientImage = 0;int HTMLView::m_instances = 0;HTMLView::HTMLView( QWidget *parentWidget, const char *widgetname, const bool DNDEnabled, const bool JScriptEnabled )        : KHTMLPart( parentWidget, widgetname ){    m_instances++;    setJavaEnabled( false );    setPluginsEnabled( false );    setDNDEnabled( DNDEnabled );    setJScriptEnabled( JScriptEnabled );    KActionCollection* ac = actionCollection();    ac->setAutoConnectShortcuts( true );    m_copy = KStdAction::copy( this, SLOT( copyText() ), ac, "htmlview_copy" );    m_selectAll = KStdAction::selectAll( this, SLOT( selectAll() ), ac, "htmlview_select_all" );    {        KPopupMenu m;        m_copy->plug( &m );        m_selectAll->plug( &m );        m_copy->unplug( &m );        m_selectAll->unplug( &m );    }    connect( this, SIGNAL( selectionChanged() ), SLOT( enableCopyAction() ) );    enableCopyAction();}HTMLView::~HTMLView(){    m_instances--;    if ( m_instances < 1 ) {        delete m_bgGradientImage;        delete m_headerGradientImage;        delete m_shadowGradientImage;    }}voidHTMLView::enableCopyAction(){    m_copy->setEnabled( hasSelection() );}voidHTMLView::selectAll(){    KHTMLPart::selectAll();}voidHTMLView::copyText(){    QString text = selectedText();    // Copy both to clipboard and X11-selection    QApplication::clipboard()->setText( text, QClipboard::Clipboard );    QApplication::clipboard()->setText( text, QClipboard::Selection );}void HTMLView::paletteChange() {    delete m_bgGradientImage;    delete m_headerGradientImage;    delete m_shadowGradientImage;    m_bgGradientImage = m_headerGradientImage = m_shadowGradientImage = 0;}QStringHTMLView::loadStyleSheet(){    QString themeName = AmarokConfig::contextBrowserStyleSheet().latin1();    const QString file = kapp->dirs()->findResource( "data","amarok/themes/" + themeName + "/stylesheet.css" );    QString styleSheet;    if ( themeName != "Default" && QFile::exists( file ) )    {        const QString CSSLocation = kapp->dirs()->findResource( "data","amarok/themes/" + themeName + "/stylesheet.css" );        QFile ExternalCSS( CSSLocation );        if ( !ExternalCSS.open( IO_ReadOnly ) )            return QString(); //FIXME: should actually return the default style sheet, then        const QString pxSize = QString::number( ContextBrowser::instance()->fontMetrics().height() - 4 );        const QString fontFamily = AmarokConfig::useCustomFonts() ?                                        AmarokConfig::contextBrowserFont().family() :                                        QApplication::font().family();        const QString text   = ContextBrowser::instance()->colorGroup().text().name();        const QString link   = ContextBrowser::instance()->colorGroup().link().name();        const QString fg     = ContextBrowser::instance()->colorGroup().highlightedText().name();        const QString bg     = ContextBrowser::instance()->colorGroup().highlight().name();        const QString base   = ContextBrowser::instance()->colorGroup().base().name();        const QColor bgColor = ContextBrowser::instance()->colorGroup().highlight();        QColor gradientColor = bgColor;        //we have to set the color for body due to a KHTML bug        //KHTML sets the base color but not the text color        styleSheet = QString( "body { margin: 8px; font-size: %1px; color: %2; background-color: %3; font-family: %4; }" )                .arg( pxSize )                .arg( text )                .arg( AmarokConfig::schemeAmarok() ? fg : gradientColor.name() )                .arg( fontFamily );        QTextStream eCSSts( &ExternalCSS );        QString tmpCSS = eCSSts.read();        ExternalCSS.close();        tmpCSS.replace( "./", KURL::fromPathOrURL( CSSLocation ).directory( false ) );        tmpCSS.replace( "AMAROK_FONTSIZE-2", pxSize );        tmpCSS.replace( "AMAROK_FONTSIZE", pxSize );        tmpCSS.replace( "AMAROK_FONTSIZE+2", pxSize );        tmpCSS.replace( "AMAROK_FONTFAMILY", fontFamily );        tmpCSS.replace( "AMAROK_TEXTCOLOR", text );        tmpCSS.replace( "AMAROK_LINKCOLOR", link );        tmpCSS.replace( "AMAROK_BGCOLOR", bg );        tmpCSS.replace( "AMAROK_FGCOLOR", fg );        tmpCSS.replace( "AMAROK_BASECOLOR", base );        tmpCSS.replace( "AMAROK_DARKBASECOLOR", ContextBrowser::instance()->colorGroup().base().dark( 120 ).name() );        tmpCSS.replace( "AMAROK_GRADIENTCOLOR", gradientColor.name() );        styleSheet += tmpCSS;    }    else    {        int pxSize = ContextBrowser::instance()->fontMetrics().height() - 4;        const QString fontFamily = AmarokConfig::useCustomFonts() ? AmarokConfig::contextBrowserFont().family() : QApplication::font().family();        const QString text = ContextBrowser::instance()->colorGroup().text().name();        const QString link = ContextBrowser::instance()->colorGroup().link().name();        const QString fg   = ContextBrowser::instance()->colorGroup().highlightedText().name();        const QString bg   = ContextBrowser::instance()->colorGroup().highlight().name();

⌨️ 快捷键说明

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