kivio

kiviotextformatdlg.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Peter Simonsson <psn@linux.se>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kiviotextformatdlg.h"
21
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqbuttongroup.h>
25#include <tqradiobutton.h>
26
27#include <tdefontdialog.h>
28#include <kcolorbutton.h>
29#include <tdelocale.h>
30
31#include "kivio_view.h"
32#include "kivio_doc.h"
33
34KivioTextFormatDlg::KivioTextFormatDlg(KivioView* parent, const char* name)
35 : KDialogBase(Tabbed, i18n("Text Format"), Ok|Cancel|Default, Ok, parent, name)
36{
37 m_valign = TQt::AlignVCenter;
38 m_halign = TQt::AlignHCenter;
39 initFontTab();
40 initPositionTab();
41}
42
43void KivioTextFormatDlg::initFontTab()
44{
45 TQFrame* tab = addPage(i18n("Font"));
46 m_fontChooser = new TDEFontChooser(tab);
47 TQLabel* textColorLbl = new TQLabel(i18n("Text color:"), tab);
48 m_textCBtn = new KColorButton(tab);
49 TQGridLayout* gl = new TQGridLayout(tab);
50 gl->setSpacing(KDialog::spacingHint());
51 gl->addMultiCellWidget(m_fontChooser, 0, 0, 0, 1);
52 gl->addWidget(textColorLbl, 1, 0);
53 gl->addWidget(m_textCBtn, 1, 1);
54}
55
56void KivioTextFormatDlg::initPositionTab()
57{
58 TQFrame* tab = addPage(i18n("Position"));
59 m_valignBGrp = new TQButtonGroup(1, TQt::Horizontal, i18n("Vertical"), tab);
60 (void) new TQRadioButton(i18n("&Top"), m_valignBGrp);
61 (void) new TQRadioButton(i18n("&Center"), m_valignBGrp);
62 (void) new TQRadioButton(i18n("&Bottom"), m_valignBGrp);
63 m_valignBGrp->setButton(1);
64 m_halignBGrp = new TQButtonGroup(1, TQt::Vertical, i18n("Horizontal"), tab);
65 (void) new TQRadioButton(i18n("&Left"), m_halignBGrp);
66 (void) new TQRadioButton(i18n("C&enter"), m_halignBGrp);
67 (void) new TQRadioButton(i18n("&Right"), m_halignBGrp);
68 m_halignBGrp->setButton(1);
69 m_preview = new TQLabel(i18n("Preview"), tab);
70 m_preview->setFrameStyle(TQFrame::Box | TQFrame::Sunken);
71 m_preview->setAlignment(m_valign | m_halign);
72 TQGridLayout* gl = new TQGridLayout(tab);
73 gl->setSpacing(KDialog::spacingHint());
74 gl->setRowStretch(0, 10);
75 gl->setColStretch(1, 10);
76 gl->addWidget(m_valignBGrp, 0, 0);
77 gl->addWidget(m_preview, 0, 1);
78 gl->addWidget(m_halignBGrp, 1, 1);
79
80 connect(m_valignBGrp, TQ_SIGNAL(clicked(int)), TQ_SLOT(updateVAlign(int)));
81 connect(m_halignBGrp, TQ_SIGNAL(clicked(int)), TQ_SLOT(updateHAlign(int)));
82}
83
84void KivioTextFormatDlg::updateVAlign(int i)
85{
86 switch(i) {
87 case 0:
88 m_valign = TQt::AlignTop;
89 break;
90 case 1:
91 m_valign = TQt::AlignVCenter;
92 break;
93 case 2:
94 m_valign = TQt::AlignBottom;
95 break;
96 }
97
98 m_preview->setAlignment(m_valign | m_halign);
99}
100
101void KivioTextFormatDlg::updateHAlign(int i)
102{
103 switch(i) {
104 case 0:
105 m_halign = TQt::AlignLeft;
106 break;
107 case 1:
108 m_halign = TQt::AlignHCenter;
109 break;
110 case 2:
111 m_halign = TQt::AlignRight;
112 break;
113 }
114
115 m_preview->setAlignment(m_valign | m_halign);
116}
117
118int KivioTextFormatDlg::valign()
119{
120 return m_valign;
121}
122
123int KivioTextFormatDlg::halign()
124{
125 return m_halign;
126}
127
128TQFont KivioTextFormatDlg::font()
129{
130 return m_fontChooser->font();
131}
132
133TQColor KivioTextFormatDlg::textColor()
134{
135 return m_textCBtn->color();
136}
137
138void KivioTextFormatDlg::setVAlign(int i)
139{
140 switch(i) {
141 case TQt::AlignTop:
142 m_valignBGrp->setButton(0);
143 break;
144 case TQt::AlignVCenter:
145 m_valignBGrp->setButton(1);
146 break;
147 case TQt::AlignBottom:
148 m_valignBGrp->setButton(2);
149 break;
150 }
151
152 m_valign = static_cast<TQt::AlignmentFlags>(i);
153 m_preview->setAlignment(m_valign | m_halign);
154}
155
156void KivioTextFormatDlg::setHAlign(int i)
157{
158 switch(i) {
159 case TQt::AlignLeft:
160 m_halignBGrp->setButton(0);
161 break;
162 case TQt::AlignHCenter:
163 m_halignBGrp->setButton(1);
164 break;
165 case TQt::AlignRight:
166 m_halignBGrp->setButton(2);
167 break;
168 }
169
170 m_halign = static_cast<TQt::AlignmentFlags>(i);
171 m_preview->setAlignment(m_valign | m_halign);
172}
173
174void KivioTextFormatDlg::setFont(TQFont f)
175{
176 m_fontChooser->setFont(f);
177}
178
179void KivioTextFormatDlg::setTextColor(TQColor c)
180{
181 m_textCBtn->setColor(c);
182}
183
184void KivioTextFormatDlg::slotDefault()
185{
186 setFont((static_cast<KivioView*>(parent()))->doc()->defaultFont());
187 setTextColor(TQColor(0, 0, 0));
188 setHAlign(TQt::AlignHCenter);
189 setVAlign(TQt::AlignVCenter);
190}
191
192#include "kiviotextformatdlg.moc"