Back to index

scribus-ng  1.3.4.dfsg+svn20071115
styleselect.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include <qgroupbox.h>
00008 #include <qtoolbutton.h>
00009 #include <qlayout.h>
00010 #include <qtooltip.h>
00011 #include <qpopupmenu.h>
00012 #include <qlabel.h>
00013 #include "mspinbox.h"
00014 
00015 #include "styleselect.h"
00016 #include "styleselect.moc"
00017 
00018 extern QPixmap loadIcon(QString nam);
00019 
00020 StrikeValues::StrikeValues( QWidget* parent ) : QGroupBox( parent, "StrikeValues" )
00021 {
00022        this->setFrameShape( QGroupBox::NoFrame );
00023        this->setTitle("");
00024        this->setColumnLayout(0, Qt::Vertical );
00025        this->layout()->setSpacing( 0 );
00026        this->layout()->setMargin( 0 );
00027        group1Layout = new QGridLayout( this->layout() );
00028        group1Layout->setAlignment( Qt::AlignTop );
00029        group1Layout->setSpacing( 3 );
00030        group1Layout->setMargin( 0 );
00031        LPos = new MSpinBox( -0.1, 100, this, 1 );
00032        LPos->setValue( -0.1 );
00033        LPos->setWrapping(true);
00034        LPos->setSpecialValueText( tr( "Auto" ) );
00035        LPosTxt = new QLabel( "Displacement", this, "XoffsetTxt" );
00036        group1Layout->addWidget( LPos, 0, 1 );
00037        group1Layout->addWidget( LPosTxt, 0 , 0 );
00038        LWidth = new MSpinBox( -0.1, 100, this, 1 );
00039        LWidth->setValue( -0.1 );
00040        LWidth->setWrapping(true);
00041        LWidth->setSpecialValueText( tr( "Auto" ) );
00042        LWidthTxt = new QLabel( "Linewidth", this, "LWidthTxt" );
00043        group1Layout->addWidget( LWidth, 1, 1 );
00044        group1Layout->addWidget( LWidthTxt, 1 , 0 );
00045        languageChange();
00046 }
00047 
00048 void StrikeValues::languageChange()
00049 {
00050        LPos->setSuffix( tr(" %"));
00051        LPosTxt->setText( tr("Displacement"));
00052        LWidth->setSuffix( tr(" %"));
00053        LWidthTxt->setText( tr("Linewidth"));
00054        LPosTxt->adjustSize();
00055        LWidthTxt->adjustSize();
00056 }
00057 
00058 UnderlineValues::UnderlineValues( QWidget* parent ) : QGroupBox( parent, "ShadowValues" )
00059 {
00060        this->setFrameShape( QGroupBox::NoFrame );
00061        this->setTitle("");
00062        this->setColumnLayout(0, Qt::Vertical );
00063        this->layout()->setSpacing( 0 );
00064        this->layout()->setMargin( 0 );
00065        group1Layout = new QGridLayout( this->layout() );
00066        group1Layout->setAlignment( Qt::AlignTop );
00067        group1Layout->setSpacing( 3 );
00068        group1Layout->setMargin( 0 );
00069        LPos = new MSpinBox( -0.1, 100, this, 1 );
00070        LPos->setValue( -0.1 );
00071        LPos->setWrapping(true);
00072        LPos->setSpecialValueText( tr( "Auto" ) );
00073        LPosTxt = new QLabel( "Displacement", this, "XoffsetTxt" );
00074        group1Layout->addWidget( LPos, 0, 1 );
00075        group1Layout->addWidget( LPosTxt, 0 , 0 );
00076        LWidth = new MSpinBox( -0.1, 100, this, 1 );
00077        LWidth->setValue( -0.1 );
00078        LWidth->setWrapping(true);
00079        LWidth->setSpecialValueText( tr( "Auto" ) );
00080        LWidthTxt = new QLabel( "Linewidth", this, "LWidthTxt" );
00081        group1Layout->addWidget( LWidth, 1, 1 );
00082        group1Layout->addWidget( LWidthTxt, 1 , 0 );
00083        languageChange();
00084 }
00085 
00086 void UnderlineValues::languageChange()
00087 {
00088        LPos->setSuffix( tr(" %"));
00089        LPosTxt->setText( tr("Displacement"));
00090        LWidth->setSuffix( tr(" %"));
00091        LWidthTxt->setText( tr("Linewidth"));
00092        LPosTxt->adjustSize();
00093        LWidthTxt->adjustSize();
00094 }
00095 
00096 OutlineValues::OutlineValues( QWidget* parent ) : QGroupBox( parent, "ShadowValues" )
00097 {
00098        this->setFrameShape( QGroupBox::NoFrame );
00099        this->setTitle("");
00100        this->setColumnLayout(0, Qt::Vertical );
00101        this->layout()->setSpacing( 0 );
00102        this->layout()->setMargin( 0 );
00103        group1Layout = new QGridLayout( this->layout() );
00104        group1Layout->setAlignment( Qt::AlignTop );
00105        group1Layout->setSpacing( 3 );
00106        group1Layout->setMargin( 0 );
00107        LWidth = new MSpinBox( 0, 100, this, 1 );
00108        LWidth->setValue( 1 );
00109        LWidthTxt = new QLabel( "Linewidth", this, "LWidthTxt" );
00110        group1Layout->addWidget( LWidth, 0, 1 );
00111        group1Layout->addWidget( LWidthTxt, 0 , 0 );
00112        languageChange();
00113 }
00114 
00115 void OutlineValues::languageChange()
00116 {
00117        LWidth->setSuffix( tr(" %"));
00118        LWidthTxt->setText( tr("Linewidth"));
00119        LWidthTxt->adjustSize();
00120 }
00121 
00122 ShadowValues::ShadowValues( QWidget* parent ) : QGroupBox( parent, "ShadowValues" )
00123 {
00124        this->setFrameShape( QGroupBox::NoFrame );
00125        this->setTitle("");
00126        this->setColumnLayout(0, Qt::Vertical );
00127        this->layout()->setSpacing( 0 );
00128        this->layout()->setMargin( 0 );
00129        group1Layout = new QGridLayout( this->layout() );
00130        group1Layout->setAlignment( Qt::AlignTop );
00131        group1Layout->setSpacing( 3 );
00132        group1Layout->setMargin( 0 );
00133        Xoffset = new MSpinBox( -100, 100, this, 1 );
00134        Xoffset->setValue( 5 );
00135        XoffsetTxt = new QLabel( "X-Offset", this, "XoffsetTxt" );
00136        group1Layout->addWidget( Xoffset, 0, 1 );
00137        group1Layout->addWidget( XoffsetTxt, 0 , 0 );
00138        Yoffset = new MSpinBox( -100, 100, this, 1 );
00139        Yoffset->setValue( 5 );
00140        YoffsetTxt = new QLabel( "Y-Offset", this, "YoffsetTxt" );
00141        group1Layout->addWidget( Yoffset, 1, 1 );
00142        group1Layout->addWidget( YoffsetTxt, 1 , 0 );
00143        languageChange();
00144 }
00145 
00146 void ShadowValues::languageChange()
00147 {
00148        Xoffset->setSuffix( tr(" %"));
00149        XoffsetTxt->setText( tr("X-Offset"));
00150        Yoffset->setSuffix( tr(" %"));
00151        YoffsetTxt->setText( tr("Y-Offset"));
00152        XoffsetTxt->adjustSize();
00153        YoffsetTxt->adjustSize();
00154 }
00155 
00156 StyleSelect::StyleSelect(QWidget* parent) : QWidget(parent, "StyleSelect")
00157 {
00158        ssLayout = new QHBoxLayout( this, 0, 0, "ssLayout");
00159        ssLayout->setSpacing( 0 );
00160        ssLayout->setMargin( 0 );
00161 
00162        UnderlineVal = new UnderlineValues( NULL );
00163        UnderlinePop = new QPopupMenu();
00164        UnderlinePop->insertItem(UnderlineVal);
00165        underlineButton = new QToolButton( this, "underlineButton" );
00166        underlineButton->setText( "" );
00167        underlineButton->setMaximumSize( QSize( 22, 22 ) );
00168        underlineButton->setPixmap(loadIcon("Unter.xpm"));
00169        underlineButton->setToggleButton( true );
00170        underlineButton->setPopup(UnderlinePop);
00171        underlineButton->setPopupDelay(400);
00172        ssLayout->addWidget( underlineButton );
00173        underlineWordButton = new QToolButton( this, "underlineButton" );
00174        underlineWordButton->setText( "" );
00175        underlineWordButton->setMaximumSize( QSize( 22, 22 ) );
00176        underlineWordButton->setPixmap(loadIcon("wordsOnly.png"));
00177        underlineWordButton->setToggleButton( true );
00178        underlineWordButton->setPopup(UnderlinePop);
00179        underlineWordButton->setPopupDelay(400);
00180        ssLayout->addWidget( underlineWordButton );
00181 
00182        subscriptButton = new QToolButton( this, "subscriptButton" );
00183        subscriptButton->setText( "" );
00184        subscriptButton->setMaximumSize( QSize( 22, 22 ) );
00185        subscriptButton->setPixmap(loadIcon("Tief.xpm"));
00186        subscriptButton->setToggleButton( true );
00187        ssLayout->addWidget( subscriptButton );
00188        superscriptButton = new QToolButton( this, "superscriptButton" );
00189        superscriptButton->setText( "" );
00190        superscriptButton->setMaximumSize( QSize( 22, 22 ) );
00191        superscriptButton->setPixmap(loadIcon("Hoch.xpm"));
00192        superscriptButton->setToggleButton( true );
00193        ssLayout->addWidget( superscriptButton );
00194 
00195        allcapsButton = new QToolButton( this, "allcapsButton" );
00196        allcapsButton->setMaximumSize( QSize( 22, 22 ) );
00197        allcapsButton->setText("");
00198        allcapsButton->setPixmap(loadIcon("AllCaps.png"));
00199        allcapsButton->setToggleButton( true );
00200        ssLayout->addWidget( allcapsButton );
00201        smallcapsButton = new QToolButton( this, "smallcapsButton" );
00202        smallcapsButton->setMaximumSize( QSize( 22, 22 ) );
00203        smallcapsButton->setText("");
00204        smallcapsButton->setPixmap(loadIcon("Kapital.xpm"));
00205        smallcapsButton->setToggleButton( true );
00206        ssLayout->addWidget( smallcapsButton );
00207 
00208        StrikeVal = new StrikeValues( NULL );
00209        StrikePop = new QPopupMenu();
00210        StrikePop->insertItem(StrikeVal);
00211        strikeoutButton = new QToolButton( this, "strikeoutButton" );
00212        strikeoutButton->setText( "" );
00213        strikeoutButton->setMaximumSize( QSize( 22, 22 ) );
00214        strikeoutButton->setPixmap(loadIcon("Strike.xpm"));
00215        strikeoutButton->setToggleButton( true );
00216        strikeoutButton->setPopup(StrikePop);
00217        strikeoutButton->setPopupDelay(400);
00218        ssLayout->addWidget( strikeoutButton );
00219 
00220        OutlineVal = new OutlineValues( NULL );
00221        OutlinePop = new QPopupMenu();
00222        OutlinePop->insertItem(OutlineVal);
00223        outlineButton = new QToolButton( this, "outlineButton" );
00224        outlineButton->setText( "" );
00225        outlineButton->setMaximumSize( QSize( 22, 22 ) );
00226        outlineButton->setPixmap(loadIcon("outlined.png"));
00227        outlineButton->setToggleButton( true );
00228        outlineButton->setPopup(OutlinePop);
00229        outlineButton->setPopupDelay(400);
00230        ssLayout->addWidget( outlineButton );
00231 
00232        ShadowVal = new ShadowValues( NULL );
00233        ShadowPop = new QPopupMenu();
00234        ShadowPop->insertItem(ShadowVal);
00235        shadowButton = new QToolButton( this, "shadowButton" );
00236        shadowButton->setText( "" );
00237        shadowButton->setMaximumSize( QSize( 22, 22 ) );
00238        shadowButton->setPixmap(loadIcon("shadow.png"));
00239        shadowButton->setToggleButton( true );
00240        shadowButton->setPopup(ShadowPop);
00241        shadowButton->setPopupDelay(400);
00242        ssLayout->addWidget( shadowButton );
00243        
00244        languageChange();
00245 
00246        connect(allcapsButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00247        connect(smallcapsButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00248        connect(underlineButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00249        connect(underlineWordButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00250        connect(subscriptButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00251        connect(strikeoutButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00252        connect(superscriptButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00253        connect(outlineButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00254        connect(shadowButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
00255 
00256        resize(minimumSizeHint());
00257 }
00258 
00259 void StyleSelect::languageChange()
00260 {
00261        ShadowVal->languageChange();
00262 
00263        QToolTip::remove(underlineButton);
00264        QToolTip::remove(underlineWordButton);
00265        QToolTip::remove(allcapsButton);
00266        QToolTip::remove(smallcapsButton);
00267        QToolTip::remove(subscriptButton);
00268        QToolTip::remove(superscriptButton);
00269        QToolTip::remove(strikeoutButton);
00270        QToolTip::remove(outlineButton);
00271        QToolTip::remove(shadowButton);
00272 
00273        QToolTip::add(underlineButton,  "<qt>" + tr("Underline Text. Hold down the button momentarily to set line width and displacement options."));
00274        QToolTip::add(underlineWordButton,  "<qt>" + tr("Underline Words Only. Hold down the button momentarily to set line width and displacement options.") + "</qt>" );
00275        QToolTip::add(allcapsButton, tr("All Caps"));
00276        QToolTip::add(smallcapsButton, tr("Small Caps"));
00277        QToolTip::add(subscriptButton, tr("Subscript"));
00278        QToolTip::add(superscriptButton, tr("Superscript"));
00279        QToolTip::add(strikeoutButton, "<qt>" + tr("Strike Out. Hold down the button momentarily to set line width and displacement options.") + "</qt>" );
00280        QToolTip::add(outlineButton, "<qt>" + tr("Outline. Hold down the button momentarily to change the outline stroke width.", "Text Style Selector") + "</qt>" );
00281        QToolTip::add(shadowButton,  "<qt>" + tr("Shadowed Text. Hold down the button momentarily to enable the offset spacing.") + "</qt>" );
00282 }
00283 
00284 void StyleSelect::setStyle(int s)
00285 {
00286        superscriptButton->setOn(false);
00287        subscriptButton->setOn(false);
00288        strikeoutButton->setOn(false);
00289        underlineButton->setOn(false);
00290        underlineWordButton->setOn(false);
00291        allcapsButton->setOn(false);
00292        smallcapsButton->setOn(false);
00293        outlineButton->setOn(false);
00294        shadowButton->setOn(false);
00295        if (s & 1)
00296               superscriptButton->setOn(true);
00297        if (s & 2)
00298               subscriptButton->setOn(true);
00299        if (s & 4)
00300               outlineButton->setOn(true);
00301        if (s & 8)
00302               underlineButton->setOn(true);
00303        if (s & 16)
00304               strikeoutButton->setOn(true);
00305        if (s & 32)
00306               allcapsButton->setOn(true);
00307        if (s & 64)
00308               smallcapsButton->setOn(true);
00309        if (s & 256)
00310               shadowButton->setOn(true);
00311        if (s & 512)
00312               underlineWordButton->setOn(true);
00313 }
00314 
00315 int StyleSelect::getStyle()
00316 {
00317        int ret = 0;
00318        if (superscriptButton->isOn())
00319               ret |= 1;
00320        if (subscriptButton->isOn())
00321               ret |= 2;
00322        if (outlineButton->isOn())
00323               ret |= 4;
00324        if (underlineButton->isOn())
00325               ret |= 8;
00326        if (strikeoutButton->isOn())
00327               ret |= 16;
00328        if (allcapsButton->isOn())
00329               ret |= 32;
00330        if (smallcapsButton->isOn())
00331               ret |= 64;
00332        if (shadowButton->isOn())
00333               ret |= 256;
00334        if (underlineWordButton->isOn())
00335               ret |= 512;
00336        return ret;
00337 }
00338 
00339 void StyleSelect::setTypeStyle()
00340 {
00341        if (superscriptButton == sender())
00342               subscriptButton->setOn(false);
00343        if (subscriptButton == sender())
00344               superscriptButton->setOn(false);
00345        if (allcapsButton == sender())
00346               smallcapsButton->setOn(false);
00347        if (smallcapsButton == sender())
00348               allcapsButton->setOn(false);
00349        if (underlineWordButton == sender())
00350               underlineButton->setOn(false);
00351        if (underlineButton == sender())
00352               underlineWordButton->setOn(false);
00353        emit State(getStyle());
00354 }
00355