kivio

kivioarrowheadformatdlg.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 "kivioarrowheadformatdlg.h"
00021 
00022 #include <qlabel.h>
00023 #include <qgroupbox.h>
00024 #include <qlayout.h>
00025 #include <qbitmap.h>
00026 #include <qpixmap.h>
00027 #include <qpainter.h>
00028 #include <qframe.h>
00029 
00030 #include <kcombobox.h>
00031 #include <klocale.h>
00032 #include <kiconloader.h>
00033 
00034 #include <KoUnitWidgets.h>
00035 
00036 #include "kivio_view.h"
00037 #include "kivioglobal.h"
00038 
00039 KivioArrowHeadFormatDlg::KivioArrowHeadFormatDlg(KivioView* parent, const char* name)
00040   : KDialogBase(parent, name, true, i18n("Arrowhead Format"), Ok|Cancel|Default, Ok)
00041 {
00042   m_unit = KoUnit::U_PT;
00043   init();
00044 }
00045 
00046 void KivioArrowHeadFormatDlg::init()
00047 {
00048   QWidget* mainWidget = new QWidget(this);
00049   setMainWidget(mainWidget);
00050   QGridLayout* gl = new QGridLayout(mainWidget, 2, 1, 0, KDialog::spacingHint());
00051 
00052   QLabel* startAHHeaderIcon = new QLabel(mainWidget);
00053   startAHHeaderIcon->setPixmap(SmallIcon("start_arrowhead", 16));
00054   startAHHeaderIcon->setFixedSize(16, 16);
00055   QLabel* startAHHeaderLabel = new QLabel(i18n("<b>Arrowhead at Origin</b>"), mainWidget);
00056   QFont font = startAHHeaderLabel->font();
00057   QFrame* startAHHeaderLine = new QFrame(mainWidget);
00058   startAHHeaderLine->setFrameStyle(QFrame::HLine|QFrame::Plain);
00059   QLabel* startAHTypeLbl = new QLabel(i18n("&Type:"), mainWidget);
00060   m_startAHTypeCBox = new KComboBox(mainWidget);
00061   loadArrowHeads(m_startAHTypeCBox);
00062   startAHTypeLbl->setBuddy(m_startAHTypeCBox);
00063   QLabel* startAHWidthLbl = new QLabel(i18n("&Width:"), mainWidget);
00064   m_startAHWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
00065   startAHWidthLbl->setBuddy(m_startAHWidthUSBox);
00066   QLabel* startAHHeightLbl = new QLabel(i18n("&Length:"), mainWidget);
00067   m_startAHHeightUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
00068   startAHHeightLbl->setBuddy(m_startAHHeightUSBox);
00069 
00070   QLabel* endAHHeaderIcon = new QLabel(mainWidget);
00071   endAHHeaderIcon->setPixmap(SmallIcon("end_arrowhead", 16));
00072   endAHHeaderIcon->setFixedSize(16, 16);
00073   QLabel* endAHHeaderLabel = new QLabel(i18n("<b>Arrowhead at End</b>"), mainWidget);
00074   QFrame* endAHHeaderLine = new QFrame(mainWidget);
00075   endAHHeaderLine->setFrameStyle(QFrame::HLine|QFrame::Plain);
00076   QLabel* endAHTypeLbl = new QLabel(i18n("T&ype:"), mainWidget);
00077   m_endAHTypeCBox = new KComboBox(mainWidget);
00078   loadArrowHeads(m_endAHTypeCBox);
00079   endAHTypeLbl->setBuddy(m_endAHTypeCBox);
00080   QLabel* endAHWidthLbl = new QLabel(i18n("W&idth:"), mainWidget);
00081   m_endAHWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
00082   endAHWidthLbl->setBuddy(m_endAHWidthUSBox);
00083   QLabel* endAHHeightLbl = new QLabel(i18n("L&ength:"), mainWidget);
00084   m_endAHHeightUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
00085   endAHHeightLbl->setBuddy(m_endAHHeightUSBox);
00086 
00087   gl->addWidget(startAHHeaderIcon, 0, 0);
00088   gl->addMultiCellWidget(startAHHeaderLabel, 0, 0, 1, 2);
00089   gl->addMultiCellWidget(startAHHeaderLine, 1, 1, 0, 2);
00090   gl->addMultiCellWidget(startAHTypeLbl, 2, 2, 0, 1);
00091   gl->addWidget(m_startAHTypeCBox, 2, 2);
00092   gl->addMultiCellWidget(startAHWidthLbl, 3, 3, 0, 1);
00093   gl->addWidget(m_startAHWidthUSBox, 3, 2);
00094   gl->addMultiCellWidget(startAHHeightLbl, 4, 4, 0, 1);
00095   gl->addWidget(m_startAHHeightUSBox, 4, 2);
00096 
00097   gl->addMultiCell(new QSpacerItem(KDialog::marginHint(), KDialog::marginHint(),
00098                    QSizePolicy::Minimum, QSizePolicy::Fixed), 5, 5, 0, 2);
00099 
00100   gl->addWidget(endAHHeaderIcon, 6, 0);
00101   gl->addMultiCellWidget(endAHHeaderLabel, 6, 6, 1, 2);
00102   gl->addMultiCellWidget(endAHHeaderLine, 7, 7, 0, 2);
00103   gl->addMultiCellWidget(endAHTypeLbl, 8, 8, 0, 1);
00104   gl->addWidget(m_endAHTypeCBox, 8, 2);
00105   gl->addMultiCellWidget(endAHWidthLbl, 9, 9, 0, 1);
00106   gl->addWidget(m_endAHWidthUSBox, 9, 2);
00107   gl->addMultiCellWidget(endAHHeightLbl, 10, 10, 0, 1);
00108   gl->addWidget(m_endAHHeightUSBox, 10, 2);
00109   gl->setRowStretch(11, 10);
00110 }
00111 
00112 void KivioArrowHeadFormatDlg::loadArrowHeads(KComboBox* combo)
00113 {
00114   QBitmap mask;
00115   QPixmap pixAll = Kivio::arrowHeadPixmap();
00116   QPixmap pix(pixAll.width(), 17);
00117   QPainter p(&pix, combo);
00118   int cindex = 0;
00119 
00120   // insert item "None"
00121   combo->insertItem(i18n("no line end", "None"),cindex++);
00122 
00123   for (int y = 0; y < pixAll.height(); y += 17 ) {
00124     p.drawPixmap(0, 0, pixAll, 0, y, pix.width(), pix.height());
00125     combo->insertItem(pix,cindex++);
00126   }
00127 
00128   p.end();
00129 }
00130 
00131 int KivioArrowHeadFormatDlg::startAHType()
00132 {
00133   return m_startAHTypeCBox->currentItem();
00134 }
00135 
00136 double KivioArrowHeadFormatDlg::startAHWidth()
00137 {
00138   return m_startAHWidthUSBox->value();
00139 }
00140 
00141 double KivioArrowHeadFormatDlg::startAHHeight()
00142 {
00143   return m_startAHHeightUSBox->value();
00144 }
00145 
00146 int KivioArrowHeadFormatDlg::endAHType()
00147 {
00148   return m_endAHTypeCBox->currentItem();
00149 }
00150 
00151 double KivioArrowHeadFormatDlg::endAHWidth()
00152 {
00153   return m_endAHWidthUSBox->value();
00154 }
00155 
00156 double KivioArrowHeadFormatDlg::endAHHeight()
00157 {
00158   return m_endAHHeightUSBox->value();
00159 }
00160 
00161 void KivioArrowHeadFormatDlg::setUnit(KoUnit::Unit u)
00162 {
00163   m_unit = u;
00164   m_startAHWidthUSBox->setUnit(u);
00165   m_startAHHeightUSBox->setUnit(u);
00166   m_endAHWidthUSBox->setUnit(u);
00167   m_endAHHeightUSBox->setUnit(u);
00168 }
00169 
00170 void KivioArrowHeadFormatDlg::setStartAHType(int t)
00171 {
00172   m_startAHTypeCBox->setCurrentItem(t);
00173 }
00174 
00175 void KivioArrowHeadFormatDlg::setStartAHWidth(double w)
00176 {
00177   m_startAHWidthUSBox->setValue(KoUnit::toUserValue(w, m_unit));
00178 }
00179 
00180 void KivioArrowHeadFormatDlg::setStartAHHeight(double h)
00181 {
00182   m_startAHHeightUSBox->setValue(KoUnit::toUserValue(h, m_unit));
00183 }
00184 
00185 void KivioArrowHeadFormatDlg::setEndAHType(int t)
00186 {
00187   m_endAHTypeCBox->setCurrentItem(t);
00188 }
00189 
00190 void KivioArrowHeadFormatDlg::setEndAHWidth(double w)
00191 {
00192   m_endAHWidthUSBox->setValue(KoUnit::toUserValue(w, m_unit));
00193 }
00194 
00195 void KivioArrowHeadFormatDlg::setEndAHHeight(double h)
00196 {
00197   m_endAHHeightUSBox->setValue(KoUnit::toUserValue(h, m_unit));
00198 }
00199 
00200 void KivioArrowHeadFormatDlg::slotDefault()
00201 {
00202   setStartAHType(0);
00203   setEndAHType(0);
00204   setStartAHWidth(10.0);
00205   setStartAHHeight(10.0);
00206   setEndAHWidth(10.0);
00207   setEndAHHeight(10.0);
00208 }
00209 
00210 #include "kivioarrowheadformatdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys