author | thufir <thufir> | 2002-07-04 16:58:16 (UTC) |
---|---|---|
committer | thufir <thufir> | 2002-07-04 16:58:16 (UTC) |
commit | d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189 (patch) (unidiff) | |
tree | d1e0a5fa80a12717b46257936ee3f8bb1b3ef89e /noncore/apps/opie-sheet/cellformat.cpp | |
parent | a53847b7d27938551bb4f1c8891e7bacc93143ee (diff) | |
download | opie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.zip opie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.tar.gz opie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.tar.bz2 |
added opie-sheet
Diffstat (limited to 'noncore/apps/opie-sheet/cellformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/cellformat.cpp | 585 |
1 files changed, 585 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp new file mode 100644 index 0000000..6a2ff72 --- a/dev/null +++ b/noncore/apps/opie-sheet/cellformat.cpp | |||
@@ -0,0 +1,585 @@ | |||
1 | #include "cellformat.h" | ||
2 | |||
3 | #include <qlistbox.h> | ||
4 | #include <qlabel.h> | ||
5 | |||
6 | #define COMBO_WIDTHS 155 | ||
7 | #define COMBO_HEIGHTS 21 | ||
8 | |||
9 | #define COLOR_COUNT 17 | ||
10 | #define STYLE_COUNT 14 | ||
11 | #define HALIGN_COUNT 3 | ||
12 | #define VALIGN_COUNT 3 | ||
13 | |||
14 | QColor qtColors[COLOR_COUNT]={Qt::black, Qt::white, Qt::darkGray, Qt::gray, Qt::lightGray, Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow, Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow}; | ||
15 | Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern}; | ||
16 | QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; | ||
17 | QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"}; | ||
18 | Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter}; | ||
19 | Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter}; | ||
20 | |||
21 | CellFormat::CellFormat(QWidget *parent=0) | ||
22 | :QDialog(parent, 0, TRUE) | ||
23 | { | ||
24 | // Main widget | ||
25 | tabs=new QTabWidget(this); | ||
26 | widgetBorders=new QWidget(tabs); | ||
27 | widgetBackground=new QWidget(tabs); | ||
28 | widgetFont=new QWidget(tabs); | ||
29 | widgetAlignment=new QWidget(tabs); | ||
30 | tabs->addTab(widgetBorders, tr("&Borders")); | ||
31 | tabs->addTab(widgetBackground, tr("Back&ground")); | ||
32 | tabs->addTab(widgetFont, tr("&Font")); | ||
33 | tabs->addTab(widgetAlignment, tr("&Alignment")); | ||
34 | |||
35 | fontDB.loadRenderers(); | ||
36 | changedFont=changedAlign=changedBrush=FALSE; | ||
37 | |||
38 | // Borders tab | ||
39 | borderEditor=new BorderEditor(widgetBorders); | ||
40 | borderEditor->setGeometry(10, 10, 215, 145); | ||
41 | connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea))); | ||
42 | |||
43 | comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); | ||
44 | comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | ||
45 | |||
46 | buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); | ||
47 | buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | ||
48 | connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults())); | ||
49 | |||
50 | // Background tab | ||
51 | frameBackground=new QFrame(widgetBackground); | ||
52 | frameBackground->setGeometry(10, 10, 215, 145); | ||
53 | frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | ||
54 | |||
55 | comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); | ||
56 | connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | ||
57 | comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | ||
58 | connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | ||
59 | |||
60 | buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); | ||
61 | buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | ||
62 | connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); | ||
63 | |||
64 | // Font tab | ||
65 | frameFont=new QFrame(widgetFont); | ||
66 | frameFont->setGeometry(10, 10, 215, 125); | ||
67 | frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | ||
68 | |||
69 | comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); | ||
70 | connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | ||
71 | comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); | ||
72 | connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | ||
73 | comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); | ||
74 | connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | ||
75 | |||
76 | checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); | ||
77 | checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | ||
78 | connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | ||
79 | checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); | ||
80 | checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | ||
81 | connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | ||
82 | |||
83 | buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); | ||
84 | buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | ||
85 | connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); | ||
86 | |||
87 | // Alignment tab | ||
88 | frameAlignment=new QFrame(widgetAlignment); | ||
89 | frameAlignment->setGeometry(10, 10, 215, 145); | ||
90 | frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | ||
91 | |||
92 | comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); | ||
93 | connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | ||
94 | comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); | ||
95 | connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | ||
96 | |||
97 | checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); | ||
98 | checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); | ||
99 | connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); | ||
100 | |||
101 | buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); | ||
102 | buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | ||
103 | connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); | ||
104 | |||
105 | // Main widget | ||
106 | box=new QVBoxLayout(this); | ||
107 | box->addWidget(tabs); | ||
108 | |||
109 | setCaption(tr("Format Cells")); | ||
110 | } | ||
111 | |||
112 | CellFormat::~CellFormat() | ||
113 | { | ||
114 | } | ||
115 | |||
116 | int CellFormat::findColorIndex(const QColor &color) | ||
117 | { | ||
118 | for (int i=0; i<COLOR_COUNT; ++i) | ||
119 | if (qtColors[i]==color) | ||
120 | return i; | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) | ||
125 | { | ||
126 | for (int i=0; i<VALIGN_COUNT; ++i) | ||
127 | if (flagsVAlign[i] & flag) | ||
128 | return i; | ||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) | ||
133 | { | ||
134 | for (int i=0; i<HALIGN_COUNT; ++i) | ||
135 | if (flagsHAlign[i] & flag) | ||
136 | return i; | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) | ||
141 | { | ||
142 | for (int i=0; i<STYLE_COUNT; ++i) | ||
143 | if (brushStyles[i]==style) | ||
144 | return i; | ||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | void CellFormat::setBrushBackground(const QBrush &brush) | ||
149 | { | ||
150 | comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); | ||
151 | comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); | ||
152 | |||
153 | QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); | ||
154 | QPainter p(&pix); | ||
155 | pix.fill(); | ||
156 | p.fillRect(pix.rect(), brush); | ||
157 | frameBackground->setBackgroundPixmap(pix); | ||
158 | |||
159 | brushBackground=brush; | ||
160 | } | ||
161 | |||
162 | void CellFormat::setTextFont(const QFont &font, const QColor &color) | ||
163 | { | ||
164 | comboFontColor->setCurrentItem(findColorIndex(color)); | ||
165 | comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); | ||
166 | comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); | ||
167 | checkFontBold->setChecked(font.weight()==QFont::Bold); | ||
168 | checkFontItalic->setChecked(font.italic()); | ||
169 | |||
170 | QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); | ||
171 | QPainter p(&pix); | ||
172 | pix.fill(); | ||
173 | p.fillRect(pix.rect(), Qt::white); | ||
174 | p.setFont(font); | ||
175 | p.setPen(color); | ||
176 | p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); | ||
177 | frameFont->setBackgroundPixmap(pix); | ||
178 | |||
179 | fontFont=font; | ||
180 | fontColor=color; | ||
181 | } | ||
182 | |||
183 | void CellFormat::setTextAlign(Qt::AlignmentFlags flags) | ||
184 | { | ||
185 | comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); | ||
186 | comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); | ||
187 | checkAlignmentWrap->setChecked(flags & Qt::WordBreak); | ||
188 | |||
189 | QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); | ||
190 | QPainter p(&pix); | ||
191 | pix.fill(); | ||
192 | p.fillRect(pix.rect(), Qt::white); | ||
193 | p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); | ||
194 | frameAlignment->setBackgroundPixmap(pix); | ||
195 | |||
196 | textAlignment=flags; | ||
197 | } | ||
198 | |||
199 | void CellFormat::slotFontDefaults() | ||
200 | { | ||
201 | changedFont=TRUE; | ||
202 | setTextFont(font(), Qt::black); | ||
203 | } | ||
204 | |||
205 | void CellFormat::slotAlignmentDefaults() | ||
206 | { | ||
207 | changedAlign=TRUE; | ||
208 | setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); | ||
209 | } | ||
210 | |||
211 | void CellFormat::slotBackgroundDefaults() | ||
212 | { | ||
213 | changedBrush=TRUE; | ||
214 | setBrushBackground(Qt::white); | ||
215 | } | ||
216 | |||
217 | void CellFormat::slotBordersDefaults() | ||
218 | { | ||
219 | QPen defaultPen(Qt::gray, 1, Qt::SolidLine); | ||
220 | borderEditor->setPen(defaultPen, BorderEditor::Top); | ||
221 | borderEditor->setPen(defaultPen, BorderEditor::Bottom); | ||
222 | borderEditor->setPen(defaultPen, BorderEditor::Left); | ||
223 | borderEditor->setPen(defaultPen, BorderEditor::Right); | ||
224 | borderEditor->setPen(defaultPen, BorderEditor::Vert); | ||
225 | borderEditor->setPen(defaultPen, BorderEditor::Horz); | ||
226 | } | ||
227 | |||
228 | void CellFormat::backgroundClicked(int index) | ||
229 | { | ||
230 | changedBrush=TRUE; | ||
231 | setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); | ||
232 | } | ||
233 | |||
234 | void CellFormat::fontClicked(bool on) | ||
235 | { | ||
236 | fontClicked(0); | ||
237 | } | ||
238 | |||
239 | void CellFormat::fontClicked(int index) | ||
240 | { | ||
241 | changedFont=TRUE; | ||
242 | setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); | ||
243 | } | ||
244 | |||
245 | void CellFormat::alignClicked(bool on) | ||
246 | { | ||
247 | alignClicked(0); | ||
248 | } | ||
249 | |||
250 | void CellFormat::alignClicked(int index) | ||
251 | { | ||
252 | changedAlign=TRUE; | ||
253 | setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); | ||
254 | } | ||
255 | |||
256 | void CellFormat::createSizeCombo(QComboBox *combo) | ||
257 | { | ||
258 | combo->clear(); | ||
259 | QValueList<int> sizes=fontDB.standardSizes(); | ||
260 | for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) | ||
261 | combo->insertItem(QString::number(*i)); | ||
262 | } | ||
263 | |||
264 | void CellFormat::borderClicked(BorderEditor::BorderArea area) | ||
265 | { | ||
266 | QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); | ||
267 | if (newPen==borderEditor->getPen(area)) | ||
268 | borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); | ||
269 | else | ||
270 | borderEditor->setPen(newPen, area); | ||
271 | } | ||
272 | |||
273 | int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) | ||
274 | { | ||
275 | for (int i=0; i<combo->count(); ++i) | ||
276 | if (combo->text(i)==item) | ||
277 | return i; | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y) | ||
282 | { | ||
283 | QComboBox *combo=new QComboBox(FALSE, parent); | ||
284 | combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); | ||
285 | combo->setSizeLimit(5); | ||
286 | |||
287 | switch (type) | ||
288 | { | ||
289 | case COMBO_WIDTH: createWidthCombo(combo); break; | ||
290 | case COMBO_STYLE: createStyleCombo(combo); break; | ||
291 | case COMBO_FONT: createFontCombo(combo); break; | ||
292 | case COMBO_SIZE: createSizeCombo(combo); break; | ||
293 | case COMBO_COLOR: createColorCombo(combo); break; | ||
294 | case COMBO_HALIGN: createHAlignCombo(combo); break; | ||
295 | case COMBO_VALIGN: createVAlignCombo(combo); break; | ||
296 | } | ||
297 | |||
298 | QLabel *label=new QLabel(combo, caption, parent); | ||
299 | label->setGeometry(10, y, 50, COMBO_HEIGHTS); | ||
300 | |||
301 | return combo; | ||
302 | } | ||
303 | |||
304 | void CellFormat::createHAlignCombo(QComboBox *combo) | ||
305 | { | ||
306 | for (int i=0; i<HALIGN_COUNT; ++i) | ||
307 | combo->insertItem(namesHAlign[i]); | ||
308 | } | ||
309 | |||
310 | void CellFormat::createVAlignCombo(QComboBox *combo) | ||
311 | { | ||
312 | for (int i=0; i<VALIGN_COUNT; ++i) | ||
313 | combo->insertItem(namesVAlign[i]); | ||
314 | } | ||
315 | |||
316 | void CellFormat::createWidthCombo(QComboBox *combo) | ||
317 | { | ||
318 | int width=combo->listBox()->maxItemWidth(); | ||
319 | QPixmap pix(width, COMBO_HEIGHTS); | ||
320 | QPainter p(&pix); | ||
321 | |||
322 | for (int i=1; i<=6; ++i) | ||
323 | { | ||
324 | pix.fill(); | ||
325 | p.setPen(QPen(Qt::black, i, Qt::SolidLine)); | ||
326 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | ||
327 | combo->insertItem(pix); | ||
328 | } | ||
329 | } | ||
330 | |||
331 | void CellFormat::createFontCombo(QComboBox *combo) | ||
332 | { | ||
333 | combo->insertStringList(fontDB.families()); | ||
334 | } | ||
335 | |||
336 | void CellFormat::createStyleCombo(QComboBox *combo) | ||
337 | { | ||
338 | int width=combo->listBox()->maxItemWidth(); | ||
339 | QPixmap pix(width, COMBO_HEIGHTS); | ||
340 | QPainter p(&pix); | ||
341 | |||
342 | for (int i=0; i<STYLE_COUNT; ++i) | ||
343 | { | ||
344 | pix.fill(); | ||
345 | p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); | ||
346 | combo->insertItem(pix); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | void CellFormat::createColorCombo(QComboBox *combo) | ||
351 | { | ||
352 | int width=combo->listBox()->maxItemWidth(); | ||
353 | QPixmap pix(width, COMBO_HEIGHTS); | ||
354 | QPainter p(&pix); | ||
355 | |||
356 | for (int i=0; i<COLOR_COUNT; ++i) | ||
357 | { | ||
358 | pix.fill(); | ||
359 | p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); | ||
360 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | ||
361 | combo->insertItem(pix); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | int CellFormat::exec(Sheet *s) | ||
366 | { | ||
367 | sheet=s; | ||
368 | int row1, row2, col1, col2, row, col; | ||
369 | sheet->getSelection(&row1, &col1, &row2, &col2); | ||
370 | |||
371 | QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), | ||
372 | penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), | ||
373 | penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), | ||
374 | penDefault=borderEditor->getDefaultPen(); | ||
375 | for (row=row1+1; row<=row2; ++row) | ||
376 | if (sheet->getPen(row, col1-1, 1)!=penLeft) | ||
377 | { | ||
378 | penLeft=penDefault; | ||
379 | break; | ||
380 | } | ||
381 | for (row=row1+1; row<=row2; ++row) | ||
382 | if (sheet->getPen(row, col2, 1)!=penRight) | ||
383 | { | ||
384 | penRight=penDefault; | ||
385 | break; | ||
386 | } | ||
387 | for (col=col1+1; col<=col2; ++col) | ||
388 | if (sheet->getPen(row1-1, col, 0)!=penTop) | ||
389 | { | ||
390 | penTop=penDefault; | ||
391 | break; | ||
392 | } | ||
393 | for (col=col1+1; col<=col2; ++col) | ||
394 | if (sheet->getPen(row2, col, 0)!=penBottom) | ||
395 | { | ||
396 | penBottom=penDefault; | ||
397 | break; | ||
398 | } | ||
399 | for (row=row1; row<=row2; ++row) | ||
400 | for (col=col1; col<col2; ++col) | ||
401 | if (sheet->getPen(row, col, 1)!=penVert) | ||
402 | { | ||
403 | penVert=penDefault; | ||
404 | break; | ||
405 | } | ||
406 | for (row=row1; row<row2; ++row) | ||
407 | for (col=col1; col<=col2; ++col) | ||
408 | if (sheet->getPen(row, col, 0)!=penHorz) | ||
409 | { | ||
410 | penHorz=penDefault; | ||
411 | break; | ||
412 | } | ||
413 | |||
414 | borderEditor->setPen(penTop, BorderEditor::Top); | ||
415 | borderEditor->setPen(penBottom, BorderEditor::Bottom); | ||
416 | borderEditor->setPen(penLeft, BorderEditor::Left); | ||
417 | borderEditor->setPen(penRight, BorderEditor::Right); | ||
418 | borderEditor->setPen(penVert, BorderEditor::Vert); | ||
419 | borderEditor->setPen(penHorz, BorderEditor::Horz); | ||
420 | |||
421 | setBrushBackground(sheet->getBrush(row1, col1)); | ||
422 | setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1)); | ||
423 | setTextAlign(sheet->getAlignment(row1, col1)); | ||
424 | |||
425 | if (QDialog::exec()==QDialog::Accepted) | ||
426 | { | ||
427 | penTop=borderEditor->getPen(BorderEditor::Top); | ||
428 | penBottom=borderEditor->getPen(BorderEditor::Bottom); | ||
429 | penLeft=borderEditor->getPen(BorderEditor::Left); | ||
430 | penRight=borderEditor->getPen(BorderEditor::Right); | ||
431 | penVert=borderEditor->getPen(BorderEditor::Vert); | ||
432 | penHorz=borderEditor->getPen(BorderEditor::Horz); | ||
433 | |||
434 | if (penTop!=penDefault) | ||
435 | for (col=col1; col<=col2; ++col) | ||
436 | sheet->setPen(row1-1, col, 0, penTop); | ||
437 | if (penBottom!=penDefault) | ||
438 | for (col=col1; col<=col2; ++col) | ||
439 | sheet->setPen(row2, col, 0, penBottom); | ||
440 | if (penLeft!=penDefault) | ||
441 | for (row=row1; row<=row2; ++row) | ||
442 | sheet->setPen(row, col1-1, 1, penLeft); | ||
443 | if (penRight!=penDefault) | ||
444 | for (row=row1; row<=row2; ++row) | ||
445 | sheet->setPen(row, col2, 1, penRight); | ||
446 | if (penVert!=penDefault) | ||
447 | for (row=row1; row<=row2; ++row) | ||
448 | for (col=col1; col<col2; ++col) | ||
449 | sheet->setPen(row, col, 1, penVert); | ||
450 | if (penHorz!=penDefault) | ||
451 | for (row=row1; row<row2; ++row) | ||
452 | for (col=col1; col<=col2; ++col) | ||
453 | sheet->setPen(row, col, 0, penHorz); | ||
454 | |||
455 | if (changedBrush) | ||
456 | { | ||
457 | for (row=row1; row<=row2; ++row) | ||
458 | for (col=col1; col<=col2; ++col) | ||
459 | sheet->setBrush(row, col, brushBackground); | ||
460 | } | ||
461 | |||
462 | if (changedAlign) | ||
463 | { | ||
464 | for (row=row1; row<=row2; ++row) | ||
465 | for (col=col1; col<=col2; ++col) | ||
466 | sheet->setTextAlign(row, col, textAlignment); | ||
467 | } | ||
468 | |||
469 | if (changedFont) | ||
470 | { | ||
471 | for (row=row1; row<=row2; ++row) | ||
472 | for (col=col1; col<=col2; ++col) | ||
473 | sheet->setTextFont(row, col, fontFont, fontColor); | ||
474 | } | ||
475 | return QDialog::Accepted; | ||
476 | } | ||
477 | return QDialog::Rejected; | ||
478 | } | ||
479 | |||
480 | // | ||
481 | // Border Editor | ||
482 | // | ||
483 | |||
484 | BorderEditor::BorderEditor(QWidget *parent=0) | ||
485 | :QFrame(parent) | ||
486 | { | ||
487 | setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | ||
488 | } | ||
489 | |||
490 | BorderEditor::~BorderEditor() | ||
491 | { | ||
492 | } | ||
493 | |||
494 | void BorderEditor::drawContents(QPainter *p) | ||
495 | { | ||
496 | QFrame::drawContents(p); | ||
497 | |||
498 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | ||
499 | int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; | ||
500 | |||
501 | p->fillRect(contentsRect(), Qt::white); | ||
502 | |||
503 | p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); | ||
504 | p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); | ||
505 | p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); | ||
506 | p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray); | ||
507 | |||
508 | if (penTop.width()>0) | ||
509 | { | ||
510 | p->setPen(penTop); | ||
511 | p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); | ||
512 | } | ||
513 | if (penBottom.width()>0) | ||
514 | { | ||
515 | p->setPen(penBottom); | ||
516 | p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); | ||
517 | } | ||
518 | if (penHorz.width()>0) | ||
519 | { | ||
520 | p->setPen(penHorz); | ||
521 | p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); | ||
522 | } | ||
523 | if (penLeft.width()>0) | ||
524 | { | ||
525 | p->setPen(penLeft); | ||
526 | p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); | ||
527 | } | ||
528 | if (penRight.width()>0) | ||
529 | { | ||
530 | p->setPen(penRight); | ||
531 | p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); | ||
532 | } | ||
533 | if (penVert.width()>0) | ||
534 | { | ||
535 | p->setPen(penVert); | ||
536 | p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | void BorderEditor::setPen(const QPen &pen, BorderArea area) | ||
541 | { | ||
542 | switch (area) | ||
543 | { | ||
544 | case Top: penTop=pen; break; | ||
545 | case Bottom: penBottom=pen; break; | ||
546 | case Left: penLeft=pen; break; | ||
547 | case Right: penRight=pen; break; | ||
548 | case Horz: penHorz=pen; break; | ||
549 | case Vert: penVert=pen; break; | ||
550 | }; | ||
551 | update(); | ||
552 | } | ||
553 | |||
554 | void BorderEditor::mouseReleaseEvent(QMouseEvent *e) | ||
555 | { | ||
556 | QFrame::mouseReleaseEvent(e); | ||
557 | |||
558 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | ||
559 | BorderArea area=None; | ||
560 | |||
561 | if (e->x()<x+width/3) area=Left; | ||
562 | if (e->x()>x+(8*width)/3) area=Right; | ||
563 | if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; | ||
564 | |||
565 | if (e->y()<y+height/3) area=Top; | ||
566 | if (e->y()>y+(8*height)/3) area=Bottom; | ||
567 | if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; | ||
568 | |||
569 | if (area!=None) | ||
570 | emit clicked(area); | ||
571 | } | ||
572 | |||
573 | QPen BorderEditor::getPen(BorderArea area) | ||
574 | { | ||
575 | switch (area) | ||
576 | { | ||
577 | case Top: return penTop; | ||
578 | case Bottom: return penBottom; | ||
579 | case Left: return penLeft; | ||
580 | case Right: return penRight; | ||
581 | case Horz: return penHorz; | ||
582 | case Vert: return penVert; | ||
583 | }; | ||
584 | return getDefaultPen(); | ||
585 | } | ||