kivio

kiviostencilformatdlg.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Peter Simonsson <psn@linux.se>
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 #include "kiviostencilformatdlg.h"
00021 
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qbitmap.h>
00025 #include <qpixmap.h>
00026 #include <qpainter.h>
00027 
00028 #include <kcolorbutton.h>
00029 #include <klocale.h>
00030 
00031 #include <KoUnitWidgets.h>
00032 
00033 #include "kivio_view.h"
00034 
00035 KivioStencilFormatDlg::KivioStencilFormatDlg(KivioView* parent, const char* name)
00036   : KDialogBase(parent, name, true, i18n("Stencil & Connector Format"), Ok|Cancel|Default, Ok)
00037 {
00038   m_unit = KoUnit::U_PT;
00039   init();
00040 }
00041 
00042 void KivioStencilFormatDlg::init()
00043 {
00044   QWidget* mainWidget = new QWidget(this);
00045   setMainWidget(mainWidget);
00046   QGridLayout* gl = new QGridLayout(mainWidget, 3, 2, KDialog::marginHint(), KDialog::spacingHint());
00047 
00048   QLabel* lineWidthLbl = new QLabel(i18n("Line &width:"), mainWidget);
00049   m_lineWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
00050   lineWidthLbl->setBuddy(m_lineWidthUSBox);
00051   QLabel* lineColorLbl = new QLabel(i18n("Line &color:"), mainWidget);
00052   m_lineCBtn = new KColorButton(mainWidget);
00053   lineColorLbl->setBuddy(m_lineCBtn);
00054   QLabel* patternLbl = new QLabel(i18n("Line &style:"), mainWidget);
00055   m_patternCBox = new KComboBox(mainWidget);
00056   patternLbl->setBuddy(m_patternCBox);
00057   initLinePatterns();
00058   QLabel* lineEndStyleLbl = new QLabel(i18n("Line &end style:"), mainWidget);
00059   m_lineEndStyleCBox = new KComboBox(mainWidget);
00060   lineEndStyleLbl->setBuddy(m_lineEndStyleCBox);
00061   initLineEndStyles();
00062   QLabel* fillColorLbl = new QLabel(i18n("&Fill color:"), mainWidget);
00063   m_fillCBtn = new KColorButton(mainWidget);
00064   fillColorLbl->setBuddy(m_fillCBtn);
00065   QLabel* fillPatternLbl = new QLabel(i18n("F&ill style:"), mainWidget);
00066   m_fillPatternCBox = new KComboBox(mainWidget);
00067   fillPatternLbl->setBuddy(m_fillPatternCBox);
00068   initFillPatterns();
00069 
00070   gl->addWidget(lineWidthLbl, 0, 0);
00071   gl->addWidget(m_lineWidthUSBox, 0, 1);
00072   gl->addWidget(lineColorLbl, 1, 0);
00073   gl->addWidget(m_lineCBtn, 1, 1);
00074   gl->addWidget(patternLbl, 2, 0);
00075   gl->addWidget(m_patternCBox, 2, 1);
00076   gl->addWidget(lineEndStyleLbl, 3, 0);
00077   gl->addWidget(m_lineEndStyleCBox, 3, 1);
00078   gl->addWidget(fillColorLbl, 4, 0);
00079   gl->addWidget(m_fillCBtn, 4, 1);
00080   gl->addWidget(fillPatternLbl, 5, 0);
00081   gl->addWidget(m_fillPatternCBox, 5, 1);
00082 }
00083 
00084 void KivioStencilFormatDlg::initLinePatterns()
00085 {
00086   QBitmap mask;
00087   QPixmap pix(m_patternCBox->width(), 17);
00088   QPainter p(&pix, m_patternCBox);
00089   QPen pen;
00090   pen.setColor(QColor(0, 0, 0));
00091   pen.setWidth(3);
00092 
00093   for (int i = NoPen; i <= DashDotDotLine ; i++ ) {
00094     pix.fill(white);
00095     pen.setStyle(static_cast<PenStyle>(i));
00096     p.setPen(pen);
00097     p.drawLine(0, 8, pix.width(), 8);
00098 
00099     mask = pix;
00100     pix.setMask(mask);
00101     m_patternCBox->insertItem(pix, i);
00102   }
00103 
00104   p.end();
00105 }
00106 
00107 void KivioStencilFormatDlg::initFillPatterns()
00108 {
00109   QBitmap mask;
00110   QPixmap pix(m_fillPatternCBox->width(), m_fillPatternCBox->fontMetrics().height() + 4);
00111   QPainter p(&pix, m_fillPatternCBox);
00112   QBrush brush;
00113   brush.setColor(QColor(0, 0, 0));
00114 
00115   for (int i = NoBrush; i <= DiagCrossPattern; i++ ) {
00116     pix.fill(white);
00117     brush.setStyle(static_cast<BrushStyle>(i));
00118     p.setBrush(brush);
00119     p.fillRect(0, 0, pix.width(), pix.height(), brush);
00120 
00121     m_fillPatternCBox->insertItem(pix, i);
00122   }
00123 
00124   p.end();
00125 }
00126 
00127 void KivioStencilFormatDlg::initLineEndStyles()
00128 {
00129   QBitmap mask;
00130   QPixmap pix(m_lineEndStyleCBox->width(), 17);
00131   QPainter p(&pix, m_lineEndStyleCBox);
00132   QPen pen;
00133   pen.setColor(QColor(0, 0, 0));
00134   pen.setWidth(4);
00135   pen.setStyle(SolidLine);
00136   pen.setJoinStyle(RoundJoin);
00137   p.setBrush(white);
00138 
00139   for (int i = 0; i < 3; i++) {
00140     pix.fill(white);
00141     pen.setCapStyle(static_cast<PenCapStyle>(i * 0x10));
00142     p.setPen(pen);
00143     p.drawLine(6, 8, pix.width() - 12, 8);
00144 
00145     mask = pix;
00146     pix.setMask(mask);
00147     m_lineEndStyleCBox->insertItem(pix, i);
00148   }
00149 
00150   p.end();
00151 }
00152 
00153 double KivioStencilFormatDlg::lineWidth()
00154 {
00155   return m_lineWidthUSBox->value();
00156 }
00157 
00158 QColor KivioStencilFormatDlg::lineColor()
00159 {
00160   return m_lineCBtn->color();
00161 }
00162 
00163 int KivioStencilFormatDlg::linePattern()
00164 {
00165   return m_patternCBox->currentItem();
00166 }
00167 
00168 QColor KivioStencilFormatDlg::fillColor()
00169 {
00170   return m_fillCBtn->color();
00171 }
00172 
00173 int KivioStencilFormatDlg::fillPattern()
00174 {
00175   return m_fillPatternCBox->currentItem();
00176 }
00177 
00178 int KivioStencilFormatDlg::lineEndStyle()
00179 {
00180   return m_lineEndStyleCBox->currentItem() * 0x10;
00181 }
00182 
00183 void KivioStencilFormatDlg::setLineWidth(double w, KoUnit::Unit u)
00184 {
00185   m_unit = u;
00186   m_lineWidthUSBox->setUnit(u);
00187   m_lineWidthUSBox->setValue(KoUnit::toUserValue(w, u));
00188 }
00189 
00190 void KivioStencilFormatDlg::setLineColor(QColor c)
00191 {
00192   m_lineCBtn->setColor(c);
00193 }
00194 
00195 void KivioStencilFormatDlg::setLinePattern(int p)
00196 {
00197   m_patternCBox->setCurrentItem(p);
00198 }
00199 
00200 void KivioStencilFormatDlg::setFillColor(QColor c)
00201 {
00202   m_fillCBtn->setColor(c);
00203 }
00204 
00205 void KivioStencilFormatDlg::setFillPattern(int p)
00206 {
00207   m_fillPatternCBox->setCurrentItem(p);
00208 }
00209 
00210 void KivioStencilFormatDlg::setLineEndStyle(int s)
00211 {
00212   m_lineEndStyleCBox->setCurrentItem(s / 0x10);
00213 }
00214 
00215 void KivioStencilFormatDlg::slotDefault()
00216 {
00217   setLineWidth(1.0, m_unit);
00218   setLineColor(QColor(0, 0, 0));
00219   setLinePattern(1);
00220   setFillColor(QColor(255, 255, 255));
00221   setFillPattern(1);
00222 }
00223 
00224 #include "kiviostencilformatdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys