You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
305 lines
7.6 KiB
305 lines
7.6 KiB
15 years ago
|
/**********************************************************************
|
||
|
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||
|
**
|
||
14 years ago
|
** This file is part of TQt Designer.
|
||
15 years ago
|
**
|
||
|
** 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.
|
||
|
**
|
||
14 years ago
|
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
|
||
|
** licenses may use this file in accordance with the TQt Commercial License
|
||
15 years ago
|
** Agreement provided with the Software.
|
||
|
**
|
||
|
** 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.
|
||
|
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
||
14 years ago
|
** information about TQt Commercial License Agreements.
|
||
15 years ago
|
**
|
||
|
** Contact info@trolltech.com if any conditions of this licensing are
|
||
|
** not clear to you.
|
||
|
**
|
||
|
**********************************************************************/
|
||
|
|
||
|
#include "paletteeditorimpl.h"
|
||
|
#include "paletteeditoradvancedimpl.h"
|
||
|
#include "previewframe.h"
|
||
|
#include "styledbutton.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "formwindow.h"
|
||
|
|
||
15 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqapplication.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
14 years ago
|
PaletteEditor::PaletteEditor( FormWindow *fw, TQWidget * parent, const char * name, bool modal, WFlags f )
|
||
|
: PaletteEditorBase( parent, name, modal, f ), formWindow( fw )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( buttonHelp, TQT_SIGNAL( clicked() ), MainWindow::self, TQT_SLOT( showDialogHelp() ) );
|
||
15 years ago
|
|
||
15 years ago
|
editPalette = TQApplication::palette();
|
||
15 years ago
|
setPreviewPalette( editPalette );
|
||
|
|
||
15 years ago
|
buttonMainColor->setColor( editPalette.active().color( TQColorGroup::Button ) );
|
||
|
buttonMainColor2->setColor( editPalette.active().color( TQColorGroup::Background ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
PaletteEditor::~PaletteEditor()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::onTune()
|
||
|
{
|
||
|
bool ok;
|
||
15 years ago
|
TQPalette pal = PaletteEditorAdvanced::getPalette( &ok, editPalette, backgroundMode, this, "tune_palette", formWindow);
|
||
15 years ago
|
if (!ok) return;
|
||
|
|
||
|
editPalette = pal;
|
||
|
setPreviewPalette( editPalette );
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::onChooseMainColor()
|
||
|
{
|
||
|
buildPalette();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::onChoose2ndMainColor()
|
||
|
{
|
||
|
buildPalette();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::paletteSelected(int)
|
||
|
{
|
||
|
setPreviewPalette(editPalette);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQColorGroup::ColorRole PaletteEditor::centralFromItem( int item )
|
||
15 years ago
|
{
|
||
|
switch( item )
|
||
|
{
|
||
|
case 0:
|
||
15 years ago
|
return TQColorGroup::Background;
|
||
15 years ago
|
case 1:
|
||
15 years ago
|
return TQColorGroup::Foreground;
|
||
15 years ago
|
case 2:
|
||
15 years ago
|
return TQColorGroup::Button;
|
||
15 years ago
|
case 3:
|
||
15 years ago
|
return TQColorGroup::Base;
|
||
15 years ago
|
case 4:
|
||
15 years ago
|
return TQColorGroup::Text;
|
||
15 years ago
|
case 5:
|
||
15 years ago
|
return TQColorGroup::BrightText;
|
||
15 years ago
|
case 6:
|
||
15 years ago
|
return TQColorGroup::ButtonText;
|
||
15 years ago
|
case 7:
|
||
15 years ago
|
return TQColorGroup::Highlight;
|
||
15 years ago
|
case 8:
|
||
15 years ago
|
return TQColorGroup::HighlightedText;
|
||
15 years ago
|
default:
|
||
15 years ago
|
return TQColorGroup::NColorRoles;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQColorGroup::ColorRole PaletteEditor::effectFromItem( int item )
|
||
15 years ago
|
{
|
||
|
switch( item )
|
||
|
{
|
||
|
case 0:
|
||
15 years ago
|
return TQColorGroup::Light;
|
||
15 years ago
|
case 1:
|
||
15 years ago
|
return TQColorGroup::Midlight;
|
||
15 years ago
|
case 2:
|
||
15 years ago
|
return TQColorGroup::Mid;
|
||
15 years ago
|
case 3:
|
||
15 years ago
|
return TQColorGroup::Dark;
|
||
15 years ago
|
case 4:
|
||
15 years ago
|
return TQColorGroup::Shadow;
|
||
15 years ago
|
default:
|
||
15 years ago
|
return TQColorGroup::NColorRoles;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildPalette()
|
||
|
{
|
||
|
int i;
|
||
15 years ago
|
TQColorGroup cg;
|
||
|
TQColor btn = buttonMainColor->color();
|
||
|
TQColor back = buttonMainColor2->color();
|
||
|
TQPalette automake( btn, back );
|
||
15 years ago
|
|
||
|
for (i = 0; i<9; i++)
|
||
|
cg.setColor( centralFromItem(i), automake.active().color( centralFromItem(i) ) );
|
||
|
|
||
|
editPalette.setActive( cg );
|
||
|
buildActiveEffect();
|
||
|
|
||
|
cg = editPalette.inactive();
|
||
|
|
||
15 years ago
|
TQPalette temp( editPalette.active().color( TQColorGroup::Button ),
|
||
|
editPalette.active().color( TQColorGroup::Background ) );
|
||
15 years ago
|
|
||
|
for (i = 0; i<9; i++)
|
||
|
cg.setColor( centralFromItem(i), temp.inactive().color( centralFromItem(i) ) );
|
||
|
|
||
|
editPalette.setInactive( cg );
|
||
|
buildInactiveEffect();
|
||
|
|
||
|
cg = editPalette.disabled();
|
||
|
|
||
|
for (i = 0; i<9; i++)
|
||
|
cg.setColor( centralFromItem(i), temp.disabled().color( centralFromItem(i) ) );
|
||
|
|
||
|
editPalette.setDisabled( cg );
|
||
|
buildDisabledEffect();
|
||
|
|
||
|
updateStyledButtons();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildActiveEffect()
|
||
|
{
|
||
15 years ago
|
TQColorGroup cg = editPalette.active();
|
||
|
TQColor btn = cg.color( TQColorGroup::Button );
|
||
15 years ago
|
|
||
15 years ago
|
TQPalette temp( btn, btn );
|
||
15 years ago
|
|
||
|
for (int i = 0; i<5; i++)
|
||
|
cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
|
||
|
|
||
|
editPalette.setActive( cg );
|
||
|
setPreviewPalette( editPalette );
|
||
|
|
||
|
updateStyledButtons();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildInactive()
|
||
|
{
|
||
|
editPalette.setInactive( editPalette.active() );
|
||
|
buildInactiveEffect();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildInactiveEffect()
|
||
|
{
|
||
15 years ago
|
TQColorGroup cg = editPalette.inactive();
|
||
15 years ago
|
|
||
15 years ago
|
TQColor light, midlight, mid, dark, shadow;
|
||
|
TQColor btn = cg.color( TQColorGroup::Button );
|
||
15 years ago
|
|
||
|
light = btn.light(150);
|
||
|
midlight = btn.light(115);
|
||
|
mid = btn.dark(150);
|
||
|
dark = btn.dark();
|
||
|
shadow = black;
|
||
|
|
||
15 years ago
|
cg.setColor( TQColorGroup::Light, light );
|
||
|
cg.setColor( TQColorGroup::Midlight, midlight );
|
||
|
cg.setColor( TQColorGroup::Mid, mid );
|
||
|
cg.setColor( TQColorGroup::Dark, dark );
|
||
|
cg.setColor( TQColorGroup::Shadow, shadow );
|
||
15 years ago
|
|
||
|
editPalette.setInactive( cg );
|
||
|
setPreviewPalette( editPalette );
|
||
|
updateStyledButtons();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildDisabled()
|
||
|
{
|
||
15 years ago
|
TQColorGroup cg = editPalette.active();
|
||
|
cg.setColor( TQColorGroup::ButtonText, darkGray );
|
||
|
cg.setColor( TQColorGroup::Foreground, darkGray );
|
||
15 years ago
|
editPalette.setDisabled( cg );
|
||
|
|
||
|
buildDisabledEffect();
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::buildDisabledEffect()
|
||
|
{
|
||
15 years ago
|
TQColorGroup cg = editPalette.disabled();
|
||
15 years ago
|
|
||
15 years ago
|
TQColor light, midlight, mid, dark, shadow;
|
||
|
TQColor btn = cg.color( TQColorGroup::Button );
|
||
15 years ago
|
|
||
|
light = btn.light(150);
|
||
|
midlight = btn.light(115);
|
||
|
mid = btn.dark(150);
|
||
|
dark = btn.dark();
|
||
|
shadow = black;
|
||
|
|
||
15 years ago
|
cg.setColor( TQColorGroup::Light, light );
|
||
|
cg.setColor( TQColorGroup::Midlight, midlight );
|
||
|
cg.setColor( TQColorGroup::Mid, mid );
|
||
|
cg.setColor( TQColorGroup::Dark, dark );
|
||
|
cg.setColor( TQColorGroup::Shadow, shadow );
|
||
15 years ago
|
|
||
|
editPalette.setDisabled( cg );
|
||
|
setPreviewPalette( editPalette );
|
||
|
updateStyledButtons();
|
||
|
}
|
||
|
|
||
15 years ago
|
void PaletteEditor::setPreviewPalette( const TQPalette& pal )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQColorGroup cg;
|
||
15 years ago
|
|
||
|
switch (paletteCombo->currentItem()) {
|
||
|
case 0:
|
||
|
default:
|
||
|
cg = pal.active();
|
||
|
break;
|
||
|
case 1:
|
||
|
cg = pal.inactive();
|
||
|
break;
|
||
|
case 2:
|
||
|
cg = pal.disabled();
|
||
|
break;
|
||
|
}
|
||
|
previewPalette.setActive( cg );
|
||
|
previewPalette.setInactive( cg );
|
||
|
previewPalette.setDisabled( cg );
|
||
|
|
||
|
previewFrame->setPreviewPalette(previewPalette);
|
||
|
}
|
||
|
|
||
|
void PaletteEditor::updateStyledButtons()
|
||
|
{
|
||
15 years ago
|
buttonMainColor->setColor( editPalette.active().color( TQColorGroup::Button ));
|
||
|
buttonMainColor2->setColor( editPalette.active().color( TQColorGroup::Background ));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void PaletteEditor::setPal( const TQPalette& pal )
|
||
15 years ago
|
{
|
||
|
editPalette = pal;
|
||
|
setPreviewPalette( pal );
|
||
|
updateStyledButtons();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPalette PaletteEditor::pal() const
|
||
15 years ago
|
{
|
||
|
return editPalette;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPalette PaletteEditor::getPalette( bool *ok, const TQPalette &init, BackgroundMode mode,
|
||
14 years ago
|
TQWidget* parent, const char* name, FormWindow *fw )
|
||
15 years ago
|
{
|
||
14 years ago
|
PaletteEditor* dlg = new PaletteEditor( fw, parent, name, TRUE );
|
||
15 years ago
|
dlg->setupBackgroundMode( mode );
|
||
|
|
||
15 years ago
|
if ( init != TQPalette() )
|
||
15 years ago
|
dlg->setPal( init );
|
||
|
int resultCode = dlg->exec();
|
||
|
|
||
15 years ago
|
TQPalette result = init;
|
||
|
if ( resultCode == TQDialog::Accepted ) {
|
||
15 years ago
|
if ( ok )
|
||
|
*ok = TRUE;
|
||
|
result = dlg->pal();
|
||
|
} else {
|
||
|
if ( ok )
|
||
|
*ok = FALSE;
|
||
|
}
|
||
|
delete dlg;
|
||
|
return result;
|
||
|
}
|