⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paletteeditorimpl.cpp

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "paletteeditorimpl.h"#include "previewstack.h"#include "styledbutton.h"#include "pixmapchooser.h"#include <qgroupbox.h>#include <qcheckbox.h>#include <qcolordialog.h>#include <qtoolbutton.h>#include <qlistbox.h>#include <qcombobox.h>#include <qapplication.h>#include <qtabwidget.h>#include <qpushbutton.h>#include <qfiledialog.h>#include <qstring.h>#include <qscrollview.h>#include "mainwindow.h"#include "formwindow.h"/*!    Class used by PaletteEditor for bold combobox items*/class BoldListBoxText : public QListBoxText{public:    BoldListBoxText( QString text, QListBox* lb = 0 );protected:    virtual void paint( QPainter* );};BoldListBoxText::BoldListBoxText( QString text, QListBox* lb )    : QListBoxText( lb ){    setText( text );}void BoldListBoxText::paint( QPainter* painter ){    QFont f = painter->font();    f.setBold( TRUE );    painter->setFont( f );    QListBoxText::paint( painter );}static QWidget* target = 0;/*!    Constructs a PaletteEditor. By default, the apply-button will be hidden, but the    static function using a target widget can be used to enable apply.    \sa getPalette()*/PaletteEditor::PaletteEditor( FormWindow *fw, QWidget * parent, const char * name, bool modal, WFlags f )    : PaletteEditorBase( parent, name, modal, f ), formWindow( fw ){    connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );    if ( !target ) {	buttonApply->hide();    } else {	if ( !target->inherits( "QScrollView" ) )	    setupBackgroundMode( target->backgroundMode() );	else	    setupBackgroundMode( ( (QScrollView*)target )->viewport()->backgroundMode() );    }    buttonActivePixmap->setEditor( StyledButton::PixmapEditor );    buttonInactivePixmap->setEditor( StyledButton::PixmapEditor );    buttonDisabledPixmap->setEditor( StyledButton::PixmapEditor );    editPalette = target ? target->palette() : QApplication::palette();    setPreviewPalette( editPalette );    buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ) );    buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ) );    onToggleBuildAll( target ? !target->ownPalette() : TRUE );    buttonActivePixmap->setFormWindow( formWindow );    buttonInactivePixmap->setFormWindow( formWindow );    buttonDisabledPixmap->setFormWindow( formWindow );    checkBuildActiveEffect->setChecked( FALSE );    checkBuildActiveEffect->setChecked( TRUE );    checkBuildInactiveEffect->setChecked( FALSE );    checkBuildInactiveEffect->setChecked( TRUE );    checkBuildDisabledEffect->setChecked( FALSE );    checkBuildDisabledEffect->setChecked( TRUE );}PaletteEditor::~PaletteEditor(){}/*!    Applies current palette to target specified in static function    \sa getPalette()*/void PaletteEditor::apply(){    if ( target )	target->setPalette( editPalette );}/*!    \reimp*/void PaletteEditor::onChooseMainColor(){    buildPalette();}void PaletteEditor::onChoose2ndMainColor(){    buildPalette();}void PaletteEditor::onChooseActiveCentralColor(){    mapToActiveCentralRole( buttonActiveCentral->color() );    updateStyledButtons();}void PaletteEditor::onChooseActiveEffectColor(){    mapToActiveEffectRole( buttonActiveEffect->color() );    updateStyledButtons();}void PaletteEditor::onChooseActivePixmap(){    if ( buttonActivePixmap->pixmap() )	mapToActivePixmapRole( * buttonActivePixmap->pixmap() );    updateStyledButtons();}void PaletteEditor::onChooseInactiveCentralColor(){    mapToInactiveCentralRole( buttonInactiveCentral->color() );    updateStyledButtons();}void PaletteEditor::onChooseInactiveEffectColor(){    mapToInactiveEffectRole( buttonInactiveEffect->color() );    updateStyledButtons();}void PaletteEditor::onChooseInactivePixmap(){    if ( buttonInactivePixmap->pixmap() )	mapToInactivePixmapRole( *buttonInactivePixmap->pixmap() );    updateStyledButtons();}void PaletteEditor::onChooseDisabledCentralColor(){    mapToDisabledCentralRole( buttonDisabledCentral->color() );    updateStyledButtons();}void PaletteEditor::onChooseDisabledEffectColor(){    mapToDisabledEffectRole( buttonDisabledEffect->color() );    updateStyledButtons();}void PaletteEditor::onChooseDisabledPixmap(){    if ( buttonDisabledPixmap->pixmap() )	mapToDisabledPixmapRole( *buttonDisabledPixmap->pixmap() );    updateStyledButtons();}void PaletteEditor::onToggleBuildAll( bool on ){    groupActiveCentral->setEnabled( !on );    groupActiveEffect->setEnabled( !on );    groupInactiveCentral->setEnabled( !on ? !checkBuildInactive->isChecked() : !on );    groupInactiveEffect->setEnabled( !on ? !checkBuildInactive->isChecked() : !on );    groupInactiveAuto->setEnabled( !on );    groupDisabledCentral->setEnabled( !on ? !checkBuildDisabled->isChecked() : !on );    groupDisabledEffect->setEnabled( !on ? !checkBuildDisabled->isChecked() : !on );    groupDisabledAuto->setEnabled( !on );    if (on)	buildPalette();}void PaletteEditor::onToggleActiveBuildEffects( bool on ){    if (on)	buildActiveEffect();}void PaletteEditor::onToggleBuildInactive( bool on ){    groupInactiveCentral->setEnabled( !on );    groupInactiveEffect->setEnabled( !on );    if (on)	buildInactive();}void PaletteEditor::onToggleInactiveBuildEffects( bool on ){    if (on)	buildInactiveEffect();}void PaletteEditor::onToggleBuildDisabled( bool on ){    groupDisabledCentral->setEnabled( !on );    groupDisabledEffect->setEnabled( !on );    if (on)	buildDisabled();}void PaletteEditor::onToggleDisabledBuildEffects( bool on ){    if (on)	buildDisabledEffect();}void PaletteEditor::onTabPage( const QString& /*page*/ ){    setPreviewPalette( editPalette );}QColorGroup::ColorRole PaletteEditor::centralFromItem( int item ){    switch( item )	{	case 0:	    return QColorGroup::Background;	case 1:	    return QColorGroup::Foreground;	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:	    debug("Can't map item to colorrole");	    return QColorGroup::NColorRoles;	}}QColorGroup::ColorRole PaletteEditor::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:	    debug("Can't map item to colorrole");	    return QColorGroup::NColorRoles;	}}void PaletteEditor::onActiveCentral( int item ){    buttonActiveCentral->setColor( editPalette.active().color( centralFromItem(item) ) );    QPixmap* p = editPalette.active().brush( centralFromItem(item) ).pixmap();    if ( p )	buttonActivePixmap->setPixmap( *p );    else	buttonActivePixmap->setPixmap( QPixmap() );}void PaletteEditor::onActiveEffect( int item ){    buttonActiveEffect->setColor( editPalette.active().color( effectFromItem(item) ) );}void PaletteEditor::onInactiveCentral( int item ){    buttonInactiveCentral->setColor( editPalette.inactive().color( centralFromItem(item) ) );    QPixmap* p = editPalette.inactive().brush( centralFromItem(item) ).pixmap();    if ( p )	buttonInactivePixmap->setPixmap( *p );    else	buttonInactivePixmap->setPixmap( QPixmap() );}void PaletteEditor::onInactiveEffect( int item ){    buttonInactiveEffect->setColor( editPalette.inactive().color( effectFromItem(item) ) );}void PaletteEditor::onDisabledCentral( int item ){    buttonDisabledCentral->setColor( editPalette.disabled().color( centralFromItem(item) ) );    QPixmap* p = editPalette.disabled().brush( centralFromItem(item) ).pixmap();    if ( p )	buttonDisabledPixmap->setPixmap( *p );    else	buttonDisabledPixmap->setPixmap( QPixmap() );}void PaletteEditor::onDisabledEffect( int item ){    buttonDisabledEffect->setColor( editPalette.disabled().color( effectFromItem(item) ) );}void PaletteEditor::mapToActiveCentralRole( const QColor& c ){    QColorGroup cg = editPalette.active();    cg.setColor( centralFromItem(comboActiveCentral->currentItem()), c );    editPalette.setActive( cg );    if ( checkBuildActiveEffect->isChecked() )	buildActiveEffect();    if ( checkBuildInactive->isChecked() )	buildInactive();    if ( checkBuildDisabled->isChecked() )	buildDisabled();    setPreviewPalette( editPalette );}void PaletteEditor::mapToActiveEffectRole( const QColor& c ){    QColorGroup cg = editPalette.active();    cg.setColor( effectFromItem(comboActiveEffect->currentItem()), c );    editPalette.setActive( cg );    if ( checkBuildInactive->isChecked() )	buildInactive();    if ( checkBuildDisabled->isChecked() )	buildDisabled();

⌨️ 快捷键说明

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