summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/ui/kiviotextformatdlg.cpp
blob: 76f76c7d0ed0da7ecb00a9ac1efeb4dc5ad8477d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* This file is part of the KDE project
   Copyright (C) 2003 Peter Simonsson <psn@linux.se>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "kiviotextformatdlg.h"

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>

#include <tdefontdialog.h>
#include <kcolorbutton.h>
#include <klocale.h>

#include "kivio_view.h"
#include "kivio_doc.h"

KivioTextFormatDlg::KivioTextFormatDlg(KivioView* parent, const char* name)
  : KDialogBase(Tabbed, i18n("Text Format"), Ok|Cancel|Default, Ok, parent, name)
{
  m_valign = TQt::AlignVCenter;
  m_halign = TQt::AlignHCenter;
  initFontTab();
  initPositionTab();
}

void KivioTextFormatDlg::initFontTab()
{
  TQFrame* tab = addPage(i18n("Font"));
  m_fontChooser = new TDEFontChooser(tab);
  TQLabel* textColorLbl = new TQLabel(i18n("Text color:"), tab);
  m_textCBtn = new KColorButton(tab);
  TQGridLayout* gl = new TQGridLayout(tab);
  gl->setSpacing(KDialog::spacingHint());
  gl->addMultiCellWidget(m_fontChooser, 0, 0, 0, 1);
  gl->addWidget(textColorLbl, 1, 0);
  gl->addWidget(m_textCBtn, 1, 1);
}

void KivioTextFormatDlg::initPositionTab()
{
  TQFrame* tab = addPage(i18n("Position"));
  m_valignBGrp = new TQButtonGroup(1, Qt::Horizontal, i18n("Vertical"), tab);
  (void) new TQRadioButton(i18n("&Top"), m_valignBGrp);
  (void) new TQRadioButton(i18n("&Center"), m_valignBGrp);
  (void) new TQRadioButton(i18n("&Bottom"), m_valignBGrp);
  m_valignBGrp->setButton(1);
  m_halignBGrp = new TQButtonGroup(1, Qt::Vertical, i18n("Horizontal"), tab);
  (void) new TQRadioButton(i18n("&Left"), m_halignBGrp);
  (void) new TQRadioButton(i18n("C&enter"), m_halignBGrp);
  (void) new TQRadioButton(i18n("&Right"), m_halignBGrp);
  m_halignBGrp->setButton(1);
  m_preview = new TQLabel(i18n("Preview"), tab);
  m_preview->setFrameStyle(TQFrame::Box | TQFrame::Sunken);
  m_preview->setAlignment(m_valign | m_halign);
  TQGridLayout* gl = new TQGridLayout(tab);
  gl->setSpacing(KDialog::spacingHint());
  gl->setRowStretch(0, 10);
  gl->setColStretch(1, 10);
  gl->addWidget(m_valignBGrp, 0, 0);
  gl->addWidget(m_preview, 0, 1);
  gl->addWidget(m_halignBGrp, 1, 1);

  connect(m_valignBGrp, TQT_SIGNAL(clicked(int)), TQT_SLOT(updateVAlign(int)));
  connect(m_halignBGrp, TQT_SIGNAL(clicked(int)), TQT_SLOT(updateHAlign(int)));
}

void KivioTextFormatDlg::updateVAlign(int i)
{
  switch(i) {
    case 0:
      m_valign = TQt::AlignTop;
      break;
    case 1:
      m_valign = TQt::AlignVCenter;
      break;
    case 2:
      m_valign = TQt::AlignBottom;
      break;
  }

  m_preview->setAlignment(m_valign | m_halign);
}

void KivioTextFormatDlg::updateHAlign(int i)
{
  switch(i) {
    case 0:
      m_halign = TQt::AlignLeft;
      break;
    case 1:
      m_halign = TQt::AlignHCenter;
      break;
    case 2:
      m_halign = TQt::AlignRight;
      break;
  }

  m_preview->setAlignment(m_valign | m_halign);
}

int KivioTextFormatDlg::valign()
{
  return m_valign;
}

int KivioTextFormatDlg::halign()
{
  return m_halign;
}

TQFont KivioTextFormatDlg::font()
{
  return m_fontChooser->font();
}

TQColor KivioTextFormatDlg::textColor()
{
  return m_textCBtn->color();
}

void KivioTextFormatDlg::setVAlign(int i)
{
  switch(i) {
    case TQt::AlignTop:
      m_valignBGrp->setButton(0);
      break;
    case TQt::AlignVCenter:
      m_valignBGrp->setButton(1);
      break;
    case TQt::AlignBottom:
      m_valignBGrp->setButton(2);
      break;
  }

  m_valign = static_cast<TQt::AlignmentFlags>(i);
  m_preview->setAlignment(m_valign | m_halign);
}

void KivioTextFormatDlg::setHAlign(int i)
{
  switch(i) {
    case TQt::AlignLeft:
      m_halignBGrp->setButton(0);
      break;
    case TQt::AlignHCenter:
      m_halignBGrp->setButton(1);
      break;
    case TQt::AlignRight:
      m_halignBGrp->setButton(2);
      break;
  }

  m_halign = static_cast<TQt::AlignmentFlags>(i);
  m_preview->setAlignment(m_valign | m_halign);
}

void KivioTextFormatDlg::setFont(TQFont f)
{
  m_fontChooser->setFont(f);
}

void KivioTextFormatDlg::setTextColor(TQColor c)
{
  m_textCBtn->setColor(c);
}

void KivioTextFormatDlg::slotDefault()
{
  setFont((static_cast<KivioView*>(TQT_TQWIDGET(parent())))->doc()->defaultFont());
  setTextColor(TQColor(0, 0, 0));
  setHAlign(TQt::AlignHCenter);
  setVAlign(TQt::AlignVCenter);
}

#include "kiviotextformatdlg.moc"