karbon

vtypebuttonbox.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #if 0
00021 
00022 // 8x8 pixels
00023 
00024 static const char* const buttonnone[]={
00025 "8 8 7 1",
00026 "c c #0a0000",
00027 ". c #0a0a0a",
00028 "b c #330000",
00029 "a c #331f1f",
00030 "# c #333333",
00031 "e c #ff0000",
00032 "d c #ffffff",
00033 ".####abc",
00034 "#ddddeeb",
00035 "#dddeeea",
00036 "#ddeeed#",
00037 "#deeedd#",
00038 "aeeeddd#",
00039 "beedddd#",
00040 "cba####."};
00041 
00042 static const char* const buttonsolid[]={
00043 "8 8 1 1",
00044 ". c #000000",
00045 "........",
00046 "........",
00047 "........",
00048 "........",
00049 "........",
00050 "........",
00051 "........",
00052 "........"};
00053 
00054 static const char* const buttongradient[]={
00055 "8 8 14 1",
00056 "f c #000000",
00057 "e c #040404",
00058 ". c #0a0a0a",
00059 "d c #0f0f0f",
00060 "c c #181818",
00061 "b c #212121",
00062 "a c #292929",
00063 "# c #303030",
00064 "g c #333333",
00065 "l c #484848",
00066 "k c #787878",
00067 "j c #a7a7a7",
00068 "i c #cdcdcd",
00069 "h c #f1f1f1",
00070 ".#abcdef",
00071 "ghijkl#f",
00072 "ghijkl#f",
00073 "ghijkl#f",
00074 "ghijkl#f",
00075 "ghijkl#f",
00076 "ghijkl#f",
00077 ".#abcdef"};
00078 
00079 static const char* const buttonpattern[]={
00080 "8 8 4 1",
00081 ". c #0a0a0a",
00082 "# c #333333",
00083 "a c #a0a0a0",
00084 "b c #ffffff",
00085 ".######.",
00086 "#aabbaa#",
00087 "#aabbaa#",
00088 "#bbaabb#",
00089 "#bbaabb#",
00090 "#aabbaa#",
00091 "#aabbaa#",
00092 ".######."};
00093 
00094 #else
00095 
00096 // 16x16 pixels
00097 
00098 static const char* const buttonnone[]={
00099 "16 16 7 1",
00100 "c c #0a0000",
00101 ". c #0a0a0a",
00102 "b c #330000",
00103 "a c #331f1f",
00104 "# c #333333",
00105 "e c #ff0000",
00106 "d c #ffffff",
00107 "..########aabbcc",
00108 "..########aabbcc",
00109 "##dddddddddeeebb",
00110 "##ddddddddeeeebb",
00111 "##dddddddeeeeeaa",
00112 "##ddddddeeeeedaa",
00113 "##dddddeeeeedd##",
00114 "##ddddeeeeeddd##",
00115 "##dddeeeeedddd##",
00116 "##ddeeeeeddddd##",
00117 "aaeeeeeedddddd##",
00118 "aaeeeeeddddddd##",
00119 "bbeeeedddddddd##",
00120 "bbeeeddddddddd##",
00121 "ccbbaa########..",
00122 "ccbbaa########.."};
00123 
00124 static const char* const buttonsolid[]={
00125 "16 16 1 1",
00126 ". c #000000",
00127 "................",
00128 "................",
00129 "................",
00130 "................",
00131 "................",
00132 "................",
00133 "................",
00134 "................",
00135 "................",
00136 "................",
00137 "................",
00138 "................",
00139 "................",
00140 "................",
00141 "................",
00142 "................"};
00143 
00144 
00145 // FIXME: Smoother gradient button.
00146 
00147 static const char* const buttongradient[]={
00148 "16 16 14 1",
00149 "f c #000000",
00150 "e c #040404",
00151 ". c #0a0a0a",
00152 "d c #0f0f0f",
00153 "c c #181818",
00154 "b c #212121",
00155 "a c #292929",
00156 "# c #303030",
00157 "g c #333333",
00158 "l c #484848",
00159 "k c #787878",
00160 "j c #a7a7a7",
00161 "i c #cdcdcd",
00162 "h c #f1f1f1",
00163 "..##aabbccddeeff",
00164 "..##aabbccddeeff",
00165 "gghhiijjkkll##ff",
00166 "gghhiijjkkll##ff",
00167 "gghhiijjkkll##ff",
00168 "gghhiijjkkll##ff",
00169 "gghhiijjkkll##ff",
00170 "gghhiijjkkll##ff",
00171 "gghhiijjkkll##ff",
00172 "gghhiijjkkll##ff",
00173 "gghhiijjkkll##ff",
00174 "gghhiijjkkll##ff",
00175 "gghhiijjkkll##ff",
00176 "gghhiijjkkll##ff",
00177 "..##aabbccddeeff",
00178 "..##aabbccddeeff"};
00179 
00180 static const char* const buttonpattern[]={
00181 "16 16 4 1",
00182 ". c #0a0a0a",
00183 "# c #333333",
00184 "a c #a0a0a0",
00185 "b c #ffffffff",
00186 "..############..",
00187 "..############..",
00188 "##aaaabbbbaaaa##",
00189 "##aaaabbbbaaaa##",
00190 "##aaaabbbbaaaa##",
00191 "##aaaabbbbaaaa##",
00192 "##bbbbaaaabbbb##",
00193 "##bbbbaaaabbbb##",
00194 "##bbbbaaaabbbb##",
00195 "##bbbbaaaabbbb##",
00196 "##aaaabbbbaaaa##",
00197 "##aaaabbbbaaaa##",
00198 "##aaaabbbbaaaa##",
00199 "##aaaabbbbaaaa##",
00200 "..############..",
00201 "..############.."};
00202 
00203 #endif
00204 
00205 
00206 #include <qpixmap.h>
00207 #include <qtoolbutton.h>
00208 #include <qtooltip.h>
00209 
00210 #include <klocale.h>
00211 
00212 #include "karbon_part.h"
00213 #include "vfillcmd.h"
00214 #include "vselection.h"
00215 #include "vstrokecmd.h"
00216 
00217 #include "vtypebuttonbox.h"
00218 
00219 VTypeButtonBox::VTypeButtonBox( KarbonPart *part, 
00220                                 QWidget* parent, const char* name )
00221     : QHButtonGroup( parent, name ),
00222       m_part( part ), m_isStrokeManipulator( false )
00223 {
00224     setMaximumWidth( parent->width() - 2 );
00225 
00226     // The button for no fill
00227     QToolButton* button = new QToolButton( this );
00228     button->setPixmap( QPixmap( (const char **) buttonnone ) );
00229     button->setMaximumWidth( 14 );
00230     button->setMaximumHeight( 14 );
00231     QToolTip::add( button, i18n( "None" ) );
00232     insert( button, none );
00233 
00234     // The button for solid fill
00235     button = new QToolButton( this );
00236     button->setPixmap( QPixmap( (const char **) buttonsolid ) );
00237     button->setMaximumWidth( 14 );
00238     button->setMaximumHeight( 14 );
00239     QToolTip::add( button, i18n( "Solid" ) );
00240     insert( button, solid );
00241 
00242     // The button for gradient fill
00243     button = new QToolButton( this );
00244     button->setPixmap( QPixmap( (const char **) buttongradient ) );
00245     button->setMaximumWidth( 14 );
00246     button->setMaximumHeight( 14 );
00247     QToolTip::add( button, i18n( "Gradient" ) );
00248     insert( button, gradient );
00249 
00250     // The button for pattern fill
00251     button = new QToolButton( this );
00252     button->setPixmap( QPixmap( (const char **) buttonpattern ) );
00253     button->setMaximumWidth( 14 );
00254     button->setMaximumHeight( 14 );
00255     QToolTip::add( button, i18n( "Pattern" ) );
00256     insert( button, pattern );
00257 
00258     setInsideMargin( 1 );
00259     setInsideSpacing( 1 );
00260     connect( this, SIGNAL( clicked( int ) ),
00261              this, SLOT( slotButtonPressed( int ) ) );
00262 }
00263 
00264 void
00265 VTypeButtonBox::slotButtonPressed( int id )
00266 {
00267     if( m_part && m_part->document().selection()->objects().count() > 0 ) {
00268         if ( m_isStrokeManipulator )
00269             manipulateStrokes( id );
00270         else
00271             manipulateFills( id );
00272     }
00273 }
00274 
00275 void
00276 VTypeButtonBox::setStroke()
00277 {
00278     m_isStrokeManipulator = true;
00279 }
00280 
00281 void
00282 VTypeButtonBox::setFill()
00283 {
00284     m_isStrokeManipulator = false;
00285 }
00286 
00287 void
00288 VTypeButtonBox::manipulateFills( int id )
00289 {
00290     VFill m_fill;
00291     m_fill = *m_part->document().selection()->objects().getFirst()->fill();
00292     switch( id ){
00293     case none:
00294         m_fill.setType( VFill::none );
00295         break;
00296     case solid:
00297         m_fill.setType( VFill::solid );
00298         break;
00299     case gradient:
00300         m_fill.setType( VFill::grad );
00301         break;
00302     case pattern:
00303         m_fill.setType( VFill::patt );
00304     }
00305     m_part->addCommand( new VFillCmd( &m_part->document(), m_fill ), true );
00306 }
00307 
00308 void
00309 VTypeButtonBox::manipulateStrokes( int id )
00310 {
00311     VStroke m_stroke;
00312     m_stroke = *m_part->document().selection()->objects().getFirst()->stroke();
00313     switch( id ){
00314     case none:
00315         m_stroke.setType( VStroke::none );
00316         break;
00317     case solid:
00318         m_stroke.setType( VStroke::solid );
00319         break;
00320     case gradient:
00321         m_stroke.setType( VStroke::grad );
00322         break;
00323     case pattern:
00324         m_stroke.setType( VStroke::patt );
00325     }
00326     m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
00327 }
00328 
00329 #include "vtypebuttonbox.moc"
00330 
KDE Home | KDE Accessibility Home | Description of Access Keys