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.
175 lines
5.6 KiB
175 lines
5.6 KiB
15 years ago
|
/*
|
||
11 years ago
|
tdeiconedit - a small graphics drawing program for the KDE
|
||
15 years ago
|
Copyright ( C ) 1998 Thomas Tanghus ( tanghus@kde.org )
|
||
|
Copyright ( C ) 2002 Nadeem Hasan ( nhasan@kde.org )
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or ( at your option ) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqwhatsthis.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
11 years ago
|
#include "tdeiconcolors.h"
|
||
15 years ago
|
#include "palettetoolbar.h"
|
||
|
|
||
14 years ago
|
PaletteToolBar::PaletteToolBar( TQWidget *parent, const char *name )
|
||
12 years ago
|
: TDEToolBar( parent, name )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQWidget *base = new TQWidget( this );
|
||
15 years ago
|
|
||
15 years ago
|
TQBoxLayout::Direction d = orientation() == Qt::Horizontal?
|
||
|
TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom;
|
||
|
m_layout = new TQBoxLayout( base, d, 2, 6 );
|
||
15 years ago
|
|
||
15 years ago
|
m_lblPreview = new TQLabel( base );
|
||
|
m_lblPreview->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
|
||
15 years ago
|
m_lblPreview->setFixedHeight( 64 );
|
||
13 years ago
|
m_lblPreview->setAlignment( TQt::AlignHCenter|TQt::AlignVCenter );
|
||
15 years ago
|
TQWhatsThis::add(m_lblPreview, i18n( "Preview\n\nThis is a 1:1 preview"
|
||
15 years ago
|
" of the current icon" ) );
|
||
|
m_layout->addWidget( m_lblPreview );
|
||
|
|
||
15 years ago
|
m_currentColorView = new TQLabel( base );
|
||
|
m_currentColorView->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
|
||
15 years ago
|
m_currentColorView->setFixedHeight( 24 );
|
||
13 years ago
|
m_currentColorView->setAlignment( TQt::AlignHCenter|TQt::AlignVCenter );
|
||
15 years ago
|
TQWhatsThis::add(m_currentColorView, i18n( "Current color\n\nThis is the currently selected color" ) );
|
||
15 years ago
|
m_layout->addWidget( m_currentColorView );
|
||
|
|
||
13 years ago
|
TQVBoxLayout *vlayout = new TQVBoxLayout( m_layout, 0 );
|
||
15 years ago
|
TQLabel *l = new TQLabel( i18n( "System colors:" ), base );
|
||
13 years ago
|
vlayout->addWidget( l );
|
||
15 years ago
|
m_sysColors = new KSysColors( base );
|
||
15 years ago
|
TQWhatsThis::add(m_sysColors, i18n( "System colors\n\nHere you can select"
|
||
13 years ago
|
" colors from the TDE icon palette" ) );
|
||
15 years ago
|
|
||
13 years ago
|
vlayout->addWidget( m_sysColors );
|
||
15 years ago
|
|
||
15 years ago
|
connect( m_sysColors, TQT_SIGNAL( newColor(uint) ),
|
||
|
TQT_SIGNAL( newColor(uint) ) );
|
||
15 years ago
|
|
||
13 years ago
|
vlayout = new TQVBoxLayout( m_layout, 0 );
|
||
15 years ago
|
l = new TQLabel( i18n( "Custom colors:" ), base );
|
||
13 years ago
|
vlayout->addWidget( l );
|
||
15 years ago
|
m_customColors = new KCustomColors( base );
|
||
15 years ago
|
TQWhatsThis::add(m_customColors, i18n( "Custom colors\n\nHere you can"
|
||
15 years ago
|
" build a palette of custom colors.\nDouble-click on a box to edit"
|
||
|
" the color" ) );
|
||
|
|
||
13 years ago
|
vlayout->addWidget( m_customColors );
|
||
15 years ago
|
|
||
15 years ago
|
connect( m_customColors, TQT_SIGNAL( newColor(uint) ),
|
||
|
TQT_SIGNAL( newColor(uint) ) );
|
||
|
connect( this, TQT_SIGNAL( newColor(uint)),
|
||
|
this, TQT_SLOT(currentColorChanged(uint)));
|
||
15 years ago
|
currentColorChanged(OPAQUE_MASK|0);
|
||
|
|
||
|
setEnableContextMenu( false );
|
||
|
setMovingEnabled( false );
|
||
|
}
|
||
|
|
||
14 years ago
|
void PaletteToolBar::setOrientation( Qt::Orientation o )
|
||
15 years ago
|
{
|
||
|
if( barPos() == Floating )
|
||
|
o = o == Qt::Vertical ? Qt::Horizontal : Qt::Vertical;
|
||
|
|
||
15 years ago
|
TQBoxLayout::Direction d = o == Qt::Horizontal? TQBoxLayout::LeftToRight
|
||
|
: TQBoxLayout::TopToBottom;
|
||
15 years ago
|
m_layout->setDirection( d );
|
||
|
|
||
15 years ago
|
TQDockWindow::setOrientation( o );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void PaletteToolBar::previewChanged( const TQPixmap &p )
|
||
15 years ago
|
{
|
||
|
m_lblPreview->setPixmap( p );
|
||
|
}
|
||
|
|
||
|
void PaletteToolBar::addColors( uint n, uint *c )
|
||
|
{
|
||
|
m_customColors->clear();
|
||
|
for( uint i = 0; i < n; i++ )
|
||
|
addColor( c[ i ] );
|
||
|
}
|
||
|
|
||
|
void PaletteToolBar::addColor( uint color )
|
||
|
{
|
||
14 years ago
|
if( !m_sysColors->contains( color ) )
|
||
15 years ago
|
m_customColors->addColor( color );
|
||
|
}
|
||
|
|
||
15 years ago
|
void PaletteToolBar::setPreviewBackground( TQPixmap pixmap )
|
||
15 years ago
|
{
|
||
|
m_lblPreview->setBackgroundPixmap(pixmap);
|
||
|
}
|
||
|
|
||
15 years ago
|
void PaletteToolBar::setPreviewBackground( const TQColor& colour )
|
||
15 years ago
|
{
|
||
|
m_lblPreview->setBackgroundColor(colour);
|
||
|
}
|
||
|
|
||
|
void PaletteToolBar::currentColorChanged(uint color)
|
||
|
{
|
||
14 years ago
|
if(tqAlpha(color) == 255)
|
||
15 years ago
|
{
|
||
|
m_currentColorView->setBackgroundColor(color);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Show the colour as if drawn over a checkerboard pattern
|
||
|
const int squareWidth = 8;
|
||
14 years ago
|
const uint lightColour = tqRgb(255, 255, 255);
|
||
|
const uint darkColour = tqRgb(127, 127, 127);
|
||
15 years ago
|
|
||
15 years ago
|
TQPixmap pm(2 * squareWidth, 2 * squareWidth);
|
||
|
TQPainter p(&pm);
|
||
15 years ago
|
|
||
14 years ago
|
double alpha = tqAlpha(color) / 255.0;
|
||
15 years ago
|
|
||
14 years ago
|
int r = int(tqRed(color) * alpha + (1 - alpha) * tqRed(lightColour) + 0.5);
|
||
|
int g = int(tqGreen(color) * alpha + (1 - alpha) * tqGreen(lightColour) + 0.5);
|
||
|
int b = int(tqBlue(color) * alpha + (1 - alpha) * tqBlue(lightColour) + 0.5);
|
||
15 years ago
|
|
||
14 years ago
|
uint squareColour = tqRgb(r, g, b);
|
||
15 years ago
|
|
||
14 years ago
|
p.setPen(TQt::NoPen);
|
||
|
p.setBrush(TQColor(squareColour));
|
||
15 years ago
|
p.drawRect(0, 0, squareWidth, squareWidth);
|
||
|
p.drawRect(squareWidth, squareWidth, squareWidth, squareWidth);
|
||
|
|
||
14 years ago
|
r = int(tqRed(color) * alpha + (1 - alpha) * tqRed(darkColour) + 0.5);
|
||
|
g = int(tqGreen(color) * alpha + (1 - alpha) * tqGreen(darkColour) + 0.5);
|
||
|
b = int(tqBlue(color) * alpha + (1 - alpha) * tqBlue(darkColour) + 0.5);
|
||
15 years ago
|
|
||
14 years ago
|
squareColour = tqRgb(r, g, b);
|
||
15 years ago
|
|
||
14 years ago
|
p.setBrush(TQColor(squareColour));
|
||
15 years ago
|
p.drawRect(squareWidth, 0, squareWidth, squareWidth);
|
||
|
p.drawRect(0, squareWidth, squareWidth, squareWidth);
|
||
|
|
||
|
p.end();
|
||
|
|
||
|
m_currentColorView->setBackgroundPixmap(pm);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "palettetoolbar.moc"
|