00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <kcoloractions.h>
00021
00022
#include <qpopupmenu.h>
00023
#include <qwhatsthis.h>
00024
#include <qtooltip.h>
00025
00026
#include <kapplication.h>
00027
#include <ktoolbar.h>
00028
#include <ktoolbarbutton.h>
00029
#include <kdebug.h>
00030
00031 KColorAction::KColorAction(
const QString& text,
int accel,
00032
QObject* parent,
const char* name )
00033 : KAction( text, accel, parent, name )
00034 {
00035 typ = TextColor;
00036 init();
00037 }
00038
00039 KColorAction::KColorAction(
const QString& text,
int accel,
00040
QObject* receiver,
const char* slot,
QObject* parent,
00041
const char* name )
00042 : KAction( text, accel, receiver, slot, parent, name )
00043 {
00044 typ = TextColor;
00045 init();
00046 }
00047
00048 KColorAction::KColorAction(
const QString& text, Type type,
int accel,
00049
QObject* parent,
const char* name )
00050 : KAction( text, accel, parent, name )
00051 {
00052 typ = type;
00053 init();
00054 }
00055
00056 KColorAction::KColorAction(
const QString& text, Type type,
int accel,
00057
QObject* receiver,
const char* slot,
QObject* parent,
00058
const char* name )
00059 : KAction( text, accel, receiver, slot, parent, name )
00060 {
00061 typ = type;
00062 init();
00063 }
00064
00065 KColorAction::KColorAction(
QObject* parent,
const char* name )
00066 : KAction( parent, name )
00067 {
00068 typ = TextColor;
00069 init();
00070 }
00071
00072
void KColorAction::setColor(
const QColor &c )
00073 {
00074
if ( c == col )
00075
return;
00076
00077 col = c;
00078 createPixmap();
00079 }
00080
00081
QColor KColorAction::color()
const
00082
{
00083
return col;
00084 }
00085
00086
void KColorAction::setType( Type t )
00087 {
00088
if ( t == typ )
00089
return;
00090
00091 typ = t;
00092 createPixmap();
00093 }
00094
00095 KColorAction::Type KColorAction::type()
const
00096
{
00097
return typ;
00098 }
00099
00100
void KColorAction::init()
00101 {
00102 col = Qt::black;
00103 createPixmap();
00104 }
00105
00106
void KColorAction::createPixmap()
00107 {
00108
int r, g, b;
00109
QCString pix;
00110
QCString line;
00111
00112 col.rgb( &r, &g, &b );
00113
00114 pix =
"/* XPM */\n";
00115
00116 pix +=
"static char * text_xpm[] = {\n";
00117
00118
switch ( typ ) {
00119
case TextColor: {
00120 pix +=
"\"20 20 11 1\",\n";
00121 pix +=
"\"h c #c0c000\",\n";
00122 pix +=
"\"g c #808000\",\n";
00123 pix +=
"\"f c #c0c0ff\",\n";
00124 pix +=
"\"a c #000000\",\n";
00125 pix +=
"\"d c #ff8000\",\n";
00126 pix +=
"\". c none\",\n";
00127 pix +=
"\"e c #0000c0\",\n";
00128 pix +=
"\"i c #ffff00\",\n";
00129 line.sprintf(
"\"# c #%02X%02X%02X \",\n", r, g, b );
00130 pix += line.copy();
00131 pix +=
"\"b c #c00000\",\n";
00132 pix +=
"\"c c #ff0000\",\n";
00133 pix +=
"\"....................\",\n";
00134 pix +=
"\"....................\",\n";
00135 pix +=
"\"....................\",\n";
00136 pix +=
"\"........#...........\",\n";
00137 pix +=
"\"........#a..........\",\n";
00138 pix +=
"\".......###..........\",\n";
00139 pix +=
"\".......###a.........\",\n";
00140 pix +=
"\"......##aa#.........\",\n";
00141 pix +=
"\"......##a.#a........\",\n";
00142 pix +=
"\".....##a...#........\",\n";
00143 pix +=
"\".....#######a.......\",\n";
00144 pix +=
"\"....##aaaaaa#.......\",\n";
00145 pix +=
"\"....##a.....aaaaaaaa\",\n";
00146 pix +=
"\"...####....#abbccdda\",\n";
00147 pix +=
"\"....aaaa....abbccdda\",\n";
00148 pix +=
"\"............aee##ffa\",\n";
00149 pix +=
"\"............aee##ffa\",\n";
00150 pix +=
"\"............agghhiia\",\n";
00151 pix +=
"\"............agghhiia\",\n";
00152 pix +=
"\"............aaaaaaaa\"};\n";
00153 }
break;
00154
case FrameColor: {
00155 pix +=
"\" 20 20 3 1 \",\n";
00156
00157 pix +=
"\" c none \",\n";
00158 pix +=
"\"+ c white \",\n";
00159 line.sprintf(
"\". c #%02X%02X%02X \",\n", r, g, b );
00160 pix += line.copy();
00161
00162 pix +=
"\" \",\n";
00163 pix +=
"\" \",\n";
00164 pix +=
"\" ................ \",\n";
00165 pix +=
"\" ................ \",\n";
00166 pix +=
"\" ................ \",\n";
00167 pix +=
"\" ...++++++++++... \",\n";
00168 pix +=
"\" ...++++++++++... \",\n";
00169 pix +=
"\" ...++++++++++... \",\n";
00170 pix +=
"\" ...++++++++++... \",\n";
00171 pix +=
"\" ...++++++++++... \",\n";
00172 pix +=
"\" ...++++++++++... \",\n";
00173 pix +=
"\" ...++++++++++... \",\n";
00174 pix +=
"\" ...++++++++++... \",\n";
00175 pix +=
"\" ...++++++++++... \",\n";
00176 pix +=
"\" ...++++++++++... \",\n";
00177 pix +=
"\" ................ \",\n";
00178 pix +=
"\" ................ \",\n";
00179 pix +=
"\" ................ \",\n";
00180 pix +=
"\" \",\n";
00181 pix +=
"\" \";\n";
00182 }
break;
00183
case BackgroundColor: {
00184 pix +=
"\" 20 20 3 1 \",\n";
00185
00186 pix +=
"\" c none \",\n";
00187 pix +=
"\". c red \",\n";
00188 line.sprintf(
"\"+ c #%02X%02X%02X \",\n", r, g, b );
00189 pix += line.copy();
00190
00191 pix +=
"\" \",\n";
00192 pix +=
"\" \",\n";
00193 pix +=
"\" ................ \",\n";
00194 pix +=
"\" ................ \",\n";
00195 pix +=
"\" ..++++++++++++.. \",\n";
00196 pix +=
"\" ..++++++++++++.. \",\n";
00197 pix +=
"\" ..++++++++++++.. \",\n";
00198 pix +=
"\" ..++++++++++++.. \",\n";
00199 pix +=
"\" ..++++++++++++.. \",\n";
00200 pix +=
"\" ..++++++++++++.. \",\n";
00201 pix +=
"\" ..++++++++++++.. \",\n";
00202 pix +=
"\" ..++++++++++++.. \",\n";
00203 pix +=
"\" ..++++++++++++.. \",\n";
00204 pix +=
"\" ..++++++++++++.. \",\n";
00205 pix +=
"\" ..++++++++++++.. \",\n";
00206 pix +=
"\" ..++++++++++++.. \",\n";
00207 pix +=
"\" ................ \",\n";
00208 pix +=
"\" ................ \",\n";
00209 pix +=
"\" \",\n";
00210 pix +=
"\" \";\n";
00211 }
break;
00212 }
00213
00214
QPixmap pixmap( pix );
00215 setIconSet(
QIconSet( pixmap ) );
00216 }
00217
00218
00219 KSelectColorAction::KSelectColorAction(
const QString& text, Type type,
00220
const QObject* receiver,
const char* slot,
00221 KActionCollection* parent,
const char* name ) :
00222 KAction( text, KShortcut(), receiver, slot, parent, name ), m_type( type ),
00223 m_color(
Qt::black )
00224 {
00225 }
00226
00227 KSelectColorAction::~KSelectColorAction()
00228 {
00229 }
00230
00231
int KSelectColorAction::plug(
QWidget* w,
int index )
00232 {
00233
if (w == 0) {
00234 kdWarning() <<
"KSelectColorAction::plug called with 0 argument\n";
00235
return -1;
00236 }
00237
if (kapp && !kapp->authorizeKAction(name()))
00238
return -1;
00239
00240
if ( w->inherits(
"QPopupMenu") )
00241 {
00242
QPopupMenu* menu = static_cast<QPopupMenu*>( w );
00243
int id;
00244
00245
if ( hasIcon() )
00246 {
00247
00248
00249
00250
00251
00252
00253
00254
id = menu->insertItem( iconSet( KIcon::Small, 0 ), text(),
this,
00255 SLOT( slotActivated() ), 0, -1, index );
00256 }
00257
else
00258
id = menu->insertItem( text(),
this, SLOT( slotActivated() ),
00259 0, -1, index );
00260
00261 updateShortcut( menu,
id );
00262
00263
00264
00265
if ( !isEnabled() )
00266 menu->setItemEnabled(
id,
false );
00267
00268
if ( !whatsThis().isEmpty() )
00269 menu->setWhatsThis(
id, whatsThisWithIcon() );
00270
00271 addContainer( menu,
id );
00272 connect( menu, SIGNAL( destroyed() ),
this, SLOT( slotDestroyed() ) );
00273
00274
if ( parentCollection() )
00275 parentCollection()->connectHighlight( menu,
this );
00276
00277
return containerCount() - 1;
00278 }
00279
else if ( w->inherits(
"KToolBar" ) )
00280 {
00281 KToolBar *bar = static_cast<KToolBar *>( w );
00282
00283
int id_ = getToolButtonID();
00284 KInstance *instance;
00285
if ( parentCollection() )
00286 instance = parentCollection()->instance();
00287
else
00288 instance = KGlobal::instance();
00289
00290
if ( icon().isEmpty() )
00291 {
00292 bar->insertButton( iconSet( KIcon::Small ).pixmap(), id_, SIGNAL( clicked() ),
this,
00293 SLOT( slotActivated() ),
00294 isEnabled(), plainText(), index );
00295 }
00296
else
00297 bar->insertButton( icon(), id_, SIGNAL( clicked() ),
this,
00298 SLOT( slotActivated() ),
00299 isEnabled(), plainText(), index, instance );
00300
00301 bar->getButton( id_ )->setName(
QCString(
"toolbutton_")+name() );
00302
00303
if ( !whatsThis().isEmpty() )
00304 QWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() );
00305
00306
if ( !toolTip().isEmpty() )
00307 QToolTip::add( bar->getButton(id_), toolTip() );
00308
00309 addContainer( bar, id_ );
00310
00311 connect( bar, SIGNAL( destroyed() ),
this, SLOT( slotDestroyed() ) );
00312
00313
if ( parentCollection() )
00314 parentCollection()->connectHighlight( bar,
this );
00315
00316
return containerCount() - 1;
00317 }
00318
00319
return -1;
00320 }
00321
00322
QColor KSelectColorAction::color()
const
00323
{
00324
return m_color;
00325 }
00326
00327 KSelectColorAction::Type KSelectColorAction::type()
const
00328
{
00329
return m_type;
00330 }
00331
00332
void KSelectColorAction::setColor(
const QColor & )
00333 {
00334 }
00335
00336
void KSelectColorAction::setType( Type )
00337 {
00338 }
00339
00340
QString KSelectColorAction::whatsThisWithIcon()
const
00341
{
00342
QString text = whatsThis();
00343
if (!icon().isEmpty())
00344
return QString::fromLatin1(
"<img source=\"small|%1\"> %2").arg(icon()).arg(text);
00345
return text;
00346 }
00347
00348
#include <kcoloractions.moc>