Back to index

scribus-ng  1.3.4.dfsg+svn20071115
shadebutton.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 "shadebutton.h"
00008 #include "shadebutton.moc"
00009 #include "query.h"
00010 
00011 
00012 ShadeButton::ShadeButton(QWidget* parent) : QToolButton(parent, "ShadeButton")
00013 {
00014        QString tmp[] = {"0 %", "10 %", "20 %", "30 %", "40 %", "50 %", "60 %", "70 %", "80 %", "90 %", "100 %"};
00015        size_t array = sizeof(tmp) / sizeof(*tmp);
00016        FillSh = new QPopupMenu();
00017        FillSh->insertItem( tr("Other..."));
00018        for (uint a = 0; a < array; ++a)
00019               FillSh->insertItem(tmp[a]);
00020        setBackgroundMode(PaletteBackground);
00021        setPopup(FillSh);
00022        setPopupDelay(1);
00023        setText("100 %");
00024        FillSh->setItemChecked(FillSh->idAt(11), true);
00025 //     setAutoRaise(true);
00026        connect( FillSh, SIGNAL(activated(int)), this, SLOT(setShade(int)));
00027 }
00028 
00029 void ShadeButton::setShade(int id)
00030 {
00031        bool ok = false;
00032        uint a;
00033        int c;
00034        int b = 100;
00035        for (a = 0; a < FillSh->count(); ++a)
00036        {
00037               FillSh->setItemChecked(FillSh->idAt(a), false);
00038        }
00039        c = FillSh->indexOf(id);
00040        if (c < 0)
00041               return;
00042 
00043        FillSh->setItemChecked(id, true);
00044        if (c > 0)
00045               b = (c-1) * 10;
00046 
00047        if (b > 100)
00048               return; // no need for > 100%, fix needed by SM, Riku
00049        
00050        if (c == 0)
00051        {
00052               Query* dia = new Query(this, "New", 1, 0, tr("&Shade:"), tr("Shade"));
00053               if (dia->exec())
00054        {
00055                      c = dia->getEditText().toInt(&ok);
00056                      if (ok)
00057                             b = QMAX(QMIN(c, 100),0);
00058                      else
00059                             b = 100;
00060                      delete dia;
00061               }
00062               else
00063               {
00064                      delete dia;
00065                      return;
00066               }
00067        }
00068        setText(QString::number(b)+" %");
00069        emit clicked();
00070 }
00071 
00072 int ShadeButton::getValue()
00073 {
00074        int l = text().length();
00075        QString tx = text().remove(l-2,2);
00076        return tx.toInt();
00077 }
00078 
00079 void ShadeButton::setValue(int val)
00080 {
00081        for (uint a = 0; a < FillSh->count(); ++a)
00082               {
00083               FillSh->setItemChecked(FillSh->idAt(a), false);
00084               }
00085        if ((val % 10) == 0)
00086               FillSh->setItemChecked(FillSh->idAt(val/10+1), true);
00087        else
00088               FillSh->setItemChecked(FillSh->idAt(0), true);
00089        setText(QString::number(val)+" %");
00090 }
00091 
00092