kivio

kiviotextformatdlg.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 "kiviotextformatdlg.h"
00021 
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qbuttongroup.h>
00025 #include <qradiobutton.h>
00026 
00027 #include <kfontdialog.h>
00028 #include <kcolorbutton.h>
00029 #include <klocale.h>
00030 
00031 #include "kivio_view.h"
00032 #include "kivio_doc.h"
00033 
00034 KivioTextFormatDlg::KivioTextFormatDlg(KivioView* parent, const char* name)
00035   : KDialogBase(Tabbed, i18n("Text Format"), Ok|Cancel|Default, Ok, parent, name)
00036 {
00037   m_valign = Qt::AlignVCenter;
00038   m_halign = Qt::AlignHCenter;
00039   initFontTab();
00040   initPositionTab();
00041 }
00042 
00043 void KivioTextFormatDlg::initFontTab()
00044 {
00045   QFrame* tab = addPage(i18n("Font"));
00046   m_fontChooser = new KFontChooser(tab);
00047   QLabel* textColorLbl = new QLabel(i18n("Text color:"), tab);
00048   m_textCBtn = new KColorButton(tab);
00049   QGridLayout* gl = new QGridLayout(tab);
00050   gl->setSpacing(KDialog::spacingHint());
00051   gl->addMultiCellWidget(m_fontChooser, 0, 0, 0, 1);
00052   gl->addWidget(textColorLbl, 1, 0);
00053   gl->addWidget(m_textCBtn, 1, 1);
00054 }
00055 
00056 void KivioTextFormatDlg::initPositionTab()
00057 {
00058   QFrame* tab = addPage(i18n("Position"));
00059   m_valignBGrp = new QButtonGroup(1, Qt::Horizontal, i18n("Vertical"), tab);
00060   (void) new QRadioButton(i18n("&Top"), m_valignBGrp);
00061   (void) new QRadioButton(i18n("&Center"), m_valignBGrp);
00062   (void) new QRadioButton(i18n("&Bottom"), m_valignBGrp);
00063   m_valignBGrp->setButton(1);
00064   m_halignBGrp = new QButtonGroup(1, Qt::Vertical, i18n("Horizontal"), tab);
00065   (void) new QRadioButton(i18n("&Left"), m_halignBGrp);
00066   (void) new QRadioButton(i18n("C&enter"), m_halignBGrp);
00067   (void) new QRadioButton(i18n("&Right"), m_halignBGrp);
00068   m_halignBGrp->setButton(1);
00069   m_preview = new QLabel(i18n("Preview"), tab);
00070   m_preview->setFrameStyle(QFrame::Box | QFrame::Sunken);
00071   m_preview->setAlignment(m_valign | m_halign);
00072   QGridLayout* gl = new QGridLayout(tab);
00073   gl->setSpacing(KDialog::spacingHint());
00074   gl->setRowStretch(0, 10);
00075   gl->setColStretch(1, 10);
00076   gl->addWidget(m_valignBGrp, 0, 0);
00077   gl->addWidget(m_preview, 0, 1);
00078   gl->addWidget(m_halignBGrp, 1, 1);
00079 
00080   connect(m_valignBGrp, SIGNAL(clicked(int)), SLOT(updateVAlign(int)));
00081   connect(m_halignBGrp, SIGNAL(clicked(int)), SLOT(updateHAlign(int)));
00082 }
00083 
00084 void KivioTextFormatDlg::updateVAlign(int i)
00085 {
00086   switch(i) {
00087     case 0:
00088       m_valign = Qt::AlignTop;
00089       break;
00090     case 1:
00091       m_valign = Qt::AlignVCenter;
00092       break;
00093     case 2:
00094       m_valign = Qt::AlignBottom;
00095       break;
00096   }
00097 
00098   m_preview->setAlignment(m_valign | m_halign);
00099 }
00100 
00101 void KivioTextFormatDlg::updateHAlign(int i)
00102 {
00103   switch(i) {
00104     case 0:
00105       m_halign = Qt::AlignLeft;
00106       break;
00107     case 1:
00108       m_halign = Qt::AlignHCenter;
00109       break;
00110     case 2:
00111       m_halign = Qt::AlignRight;
00112       break;
00113   }
00114 
00115   m_preview->setAlignment(m_valign | m_halign);
00116 }
00117 
00118 int KivioTextFormatDlg::valign()
00119 {
00120   return m_valign;
00121 }
00122 
00123 int KivioTextFormatDlg::halign()
00124 {
00125   return m_halign;
00126 }
00127 
00128 QFont KivioTextFormatDlg::font()
00129 {
00130   return m_fontChooser->font();
00131 }
00132 
00133 QColor KivioTextFormatDlg::textColor()
00134 {
00135   return m_textCBtn->color();
00136 }
00137 
00138 void KivioTextFormatDlg::setVAlign(int i)
00139 {
00140   switch(i) {
00141     case Qt::AlignTop:
00142       m_valignBGrp->setButton(0);
00143       break;
00144     case Qt::AlignVCenter:
00145       m_valignBGrp->setButton(1);
00146       break;
00147     case Qt::AlignBottom:
00148       m_valignBGrp->setButton(2);
00149       break;
00150   }
00151 
00152   m_valign = static_cast<Qt::AlignmentFlags>(i);
00153   m_preview->setAlignment(m_valign | m_halign);
00154 }
00155 
00156 void KivioTextFormatDlg::setHAlign(int i)
00157 {
00158   switch(i) {
00159     case Qt::AlignLeft:
00160       m_halignBGrp->setButton(0);
00161       break;
00162     case Qt::AlignHCenter:
00163       m_halignBGrp->setButton(1);
00164       break;
00165     case Qt::AlignRight:
00166       m_halignBGrp->setButton(2);
00167       break;
00168   }
00169 
00170   m_halign = static_cast<Qt::AlignmentFlags>(i);
00171   m_preview->setAlignment(m_valign | m_halign);
00172 }
00173 
00174 void KivioTextFormatDlg::setFont(QFont f)
00175 {
00176   m_fontChooser->setFont(f);
00177 }
00178 
00179 void KivioTextFormatDlg::setTextColor(QColor c)
00180 {
00181   m_textCBtn->setColor(c);
00182 }
00183 
00184 void KivioTextFormatDlg::slotDefault()
00185 {
00186   setFont((static_cast<KivioView*>(parent()))->doc()->defaultFont());
00187   setTextColor(QColor(0, 0, 0));
00188   setHAlign(Qt::AlignHCenter);
00189   setVAlign(Qt::AlignVCenter);
00190 }
00191 
00192 #include "kiviotextformatdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys