Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cellformat.cpp

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the Opie Project
00003              .=l.            Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This program is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This program is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 /*
00030  * Opie Sheet (formerly Sheet/Qt)
00031  * by Serdar Ozler <sozler@sitebest.com>
00032  */
00033 
00034 #include "cellformat.h"
00035 
00036 /* QT */
00037 #include <qlistbox.h>
00038 #include <qlabel.h>
00039 
00040 #define COMBO_WIDTHS 155
00041 #define COMBO_HEIGHTS 21
00042 
00043 #define COLOR_COUNT 17
00044 #define STYLE_COUNT 14
00045 #define HALIGN_COUNT 3
00046 #define VALIGN_COUNT 3
00047 
00048 QColor qtColors[COLOR_COUNT]={Qt::black,Qt::white, Qt::darkGray,
00049                               Qt::gray, Qt::lightGray, Qt::red,
00050                               Qt::green, Qt::blue, Qt::cyan,
00051                               Qt::magenta, Qt::yellow,
00052                               Qt::darkRed, Qt::darkGreen,
00053                               Qt::darkBlue, Qt::darkCyan,
00054                               Qt::darkMagenta, Qt::darkYellow};
00055 
00056 Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern,
00057                                         Qt::Dense1Pattern, Qt::Dense2Pattern,
00058                                         Qt::Dense3Pattern, Qt::Dense4Pattern,
00059                                         Qt::Dense5Pattern, Qt::Dense6Pattern,
00060                                         Qt::Dense7Pattern, Qt::HorPattern,
00061                                         Qt::VerPattern, Qt::CrossPattern,
00062                                         Qt::BDiagPattern, Qt::FDiagPattern,
00063                                         Qt::DiagCrossPattern};
00064 
00065 QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"};
00066 QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"};
00067 
00068 Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft,
00069         Qt::AlignRight,
00070         Qt::AlignHCenter};
00071 
00072 Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop,
00073         Qt::AlignBottom,
00074         Qt::AlignVCenter};
00075 
00076 CellFormat::CellFormat(QWidget *parent)
00077         :QDialog(parent, 0, TRUE)
00078 {
00079     // Main widget
00080     tabs=new QTabWidget(this);
00081     widgetBorders=new QWidget(tabs);
00082     widgetBackground=new QWidget(tabs);
00083     widgetFont=new QWidget(tabs);
00084     widgetAlignment=new QWidget(tabs);
00085     tabs->addTab(widgetBorders, tr("&Borders"));
00086     tabs->addTab(widgetBackground, tr("Back&ground"));
00087     tabs->addTab(widgetFont, tr("&Font"));
00088     tabs->addTab(widgetAlignment, tr("&Alignment"));
00089 
00090     fontDB.loadRenderers();
00091     changedFont=changedAlign=changedBrush=FALSE;
00092 
00093     // Borders tab
00094     borderEditor=new BorderEditor(widgetBorders);
00095     borderEditor->setGeometry(10, 10, 215, 145);
00096     connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)),
00097             this, SLOT(borderClicked(BorderEditor::BorderArea)));
00098 
00099     comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165);
00100     comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
00101 
00102     buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders);
00103     buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10),
00104                                        110, COMBO_HEIGHTS);
00105 
00106     connect(buttonBordersDefaults, SIGNAL(clicked()),
00107             this, SLOT(slotBordersDefaults()));
00108 
00109     // Background tab
00110     frameBackground=new QFrame(widgetBackground);
00111     frameBackground->setGeometry(10, 10, 215, 145);
00112     frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00113 
00114     comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165);
00115     connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
00116     comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
00117     connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
00118 
00119     buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground);
00120     buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
00121     connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults()));
00122 
00123     // Font tab
00124     frameFont=new QFrame(widgetFont);
00125     frameFont->setGeometry(10, 10, 215, 125);
00126     frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00127 
00128     comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145);
00129     connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
00130     comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10));
00131     connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
00132     comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10));
00133     connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
00134 
00135     checkFontBold=new QCheckBox(tr("&Bold"), widgetFont);
00136     checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
00137     connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
00138     checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont);
00139     checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
00140     connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
00141 
00142     buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont);
00143     buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
00144     connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults()));
00145 
00146     // Alignment tab
00147     frameAlignment=new QFrame(widgetAlignment);
00148     frameAlignment->setGeometry(10, 10, 215, 145);
00149     frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00150 
00151     comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165);
00152     connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
00153     comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10));
00154     connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
00155 
00156     checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment);
00157     checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS);
00158     connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool)));
00159 
00160     buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment);
00161     buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
00162     connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults()));
00163 
00164     // Main widget
00165     box=new QVBoxLayout(this);
00166     box->addWidget(tabs);
00167 
00168     setCaption(tr("Format Cells"));
00169 }
00170 
00171 CellFormat::~CellFormat()
00172 {}
00173 
00174 int CellFormat::findColorIndex(const QColor &color)
00175 {
00176     for (int i=0; i<COLOR_COUNT; ++i)
00177         if (qtColors[i]==color)
00178             return i;
00179     return 0;
00180 }
00181 
00182 int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag)
00183 {
00184     for (int i=0; i<VALIGN_COUNT; ++i)
00185         if (flagsVAlign[i] & flag)
00186             return i;
00187     return 0;
00188 }
00189 
00190 int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag)
00191 {
00192     for (int i=0; i<HALIGN_COUNT; ++i)
00193         if (flagsHAlign[i] & flag)
00194             return i;
00195     return 0;
00196 }
00197 
00198 int CellFormat::findBrushStyleIndex(Qt::BrushStyle style)
00199 {
00200     for (int i=0; i<STYLE_COUNT; ++i)
00201         if (brushStyles[i]==style)
00202             return i;
00203     return 0;
00204 }
00205 
00206 void CellFormat::setBrushBackground(const QBrush &brush)
00207 {
00208     comboBackgroundColor->setCurrentItem(findColorIndex(brush.color()));
00209     comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style()));
00210 
00211     QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height());
00212     QPainter p(&pix);
00213     pix.fill();
00214     p.fillRect(pix.rect(), brush);
00215     frameBackground->setBackgroundPixmap(pix);
00216 
00217     brushBackground=brush;
00218 }
00219 
00220 void CellFormat::setTextFont(const QFont &font, const QColor &color)
00221 {
00222     comboFontColor->setCurrentItem(findColorIndex(color));
00223     comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family()));
00224     comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize())));
00225     checkFontBold->setChecked(font.weight()==QFont::Bold);
00226     checkFontItalic->setChecked(font.italic());
00227 
00228     QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height());
00229     QPainter p(&pix);
00230     pix.fill();
00231     p.fillRect(pix.rect(), Qt::white);
00232     p.setFont(font);
00233     p.setPen(color);
00234     p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet"));
00235     frameFont->setBackgroundPixmap(pix);
00236 
00237     fontFont=font;
00238     fontColor=color;
00239 }
00240 
00241 void CellFormat::setTextAlign(Qt::AlignmentFlags flags)
00242 {
00243     comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags));
00244     comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags));
00245     checkAlignmentWrap->setChecked(flags & Qt::WordBreak);
00246 
00247     QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height());
00248     QPainter p(&pix);
00249     pix.fill();
00250     p.fillRect(pix.rect(), Qt::white);
00251     p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet"));
00252     frameAlignment->setBackgroundPixmap(pix);
00253 
00254     textAlignment=flags;
00255 }
00256 
00257 void CellFormat::slotFontDefaults()
00258 {
00259     changedFont=TRUE;
00260     setTextFont(font(), Qt::black);
00261 }
00262 
00263 void CellFormat::slotAlignmentDefaults()
00264 {
00265     changedAlign=TRUE;
00266     setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop));
00267 }
00268 
00269 void CellFormat::slotBackgroundDefaults()
00270 {
00271     changedBrush=TRUE;
00272     setBrushBackground(Qt::white);
00273 }
00274 
00275 void CellFormat::slotBordersDefaults()
00276 {
00277     QPen defaultPen(Qt::gray, 1, Qt::SolidLine);
00278     borderEditor->setPen(defaultPen, BorderEditor::Top);
00279     borderEditor->setPen(defaultPen, BorderEditor::Bottom);
00280     borderEditor->setPen(defaultPen, BorderEditor::Left);
00281     borderEditor->setPen(defaultPen, BorderEditor::Right);
00282     borderEditor->setPen(defaultPen, BorderEditor::Vert);
00283     borderEditor->setPen(defaultPen, BorderEditor::Horz);
00284 }
00285 
00286 void CellFormat::backgroundClicked(int index)
00287 {
00288     changedBrush=TRUE;
00289     setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()]));
00290 }
00291 
00292 void CellFormat::fontClicked(bool on)
00293 {
00294     fontClicked(0);
00295 }
00296 
00297 void CellFormat::fontClicked(int index)
00298 {
00299     changedFont=TRUE;
00300     setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]);
00301 }
00302 
00303 void CellFormat::alignClicked(bool on)
00304 {
00305     alignClicked(0);
00306 }
00307 
00308 void CellFormat::alignClicked(int index)
00309 {
00310     changedAlign=TRUE;
00311     setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0)));
00312 }
00313 
00314 void CellFormat::createSizeCombo(QComboBox *combo)
00315 {
00316     combo->clear();
00317     QValueList<int> sizes=fontDB.standardSizes();
00318     for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i)
00319         combo->insertItem(QString::number(*i));
00320 }
00321 
00322 void CellFormat::borderClicked(BorderEditor::BorderArea area)
00323 {
00324     QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine);
00325     if (newPen==borderEditor->getPen(area))
00326         borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area);
00327     else
00328         borderEditor->setPen(newPen, area);
00329 }
00330 
00331 int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item)
00332 {
00333     for (int i=0; i<combo->count(); ++i)
00334         if (combo->text(i)==item)
00335             return i;
00336     return 0;
00337 }
00338 
00339 QComboBox *CellFormat::createCombo(comboType type, QWidget *parent,
00340                                    const QString &caption, int y)
00341 {
00342     QComboBox *combo=new QComboBox(FALSE, parent);
00343     combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS);
00344     combo->setSizeLimit(5);
00345 
00346     switch (type)
00347     {
00348     case COMBO_WIDTH: createWidthCombo(combo); break;
00349     case COMBO_STYLE: createStyleCombo(combo); break;
00350     case COMBO_FONT: createFontCombo(combo); break;
00351     case COMBO_SIZE: createSizeCombo(combo); break;
00352     case COMBO_COLOR: createColorCombo(combo); break;
00353     case COMBO_HALIGN: createHAlignCombo(combo); break;
00354     case COMBO_VALIGN: createVAlignCombo(combo); break;
00355     default: break;
00356     }
00357 
00358     QLabel *label=new QLabel(combo, caption, parent);
00359     label->setGeometry(10, y, 50, COMBO_HEIGHTS);
00360 
00361     return combo;
00362 }
00363 
00364 void CellFormat::createHAlignCombo(QComboBox *combo)
00365 {
00366     for (int i=0; i<HALIGN_COUNT; ++i)
00367         combo->insertItem(namesHAlign[i]);
00368 }
00369 
00370 void CellFormat::createVAlignCombo(QComboBox *combo)
00371 {
00372     for (int i=0; i<VALIGN_COUNT; ++i)
00373         combo->insertItem(namesVAlign[i]);
00374 }
00375 
00376 void CellFormat::createWidthCombo(QComboBox *combo)
00377 {
00378     int width=combo->listBox()->maxItemWidth();
00379     QPixmap pix(width, COMBO_HEIGHTS);
00380     QPainter p(&pix);
00381 
00382     for (int i=1; i<=6; ++i)
00383     {
00384         pix.fill();
00385         p.setPen(QPen(Qt::black, i, Qt::SolidLine));
00386         p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
00387         combo->insertItem(pix);
00388     }
00389 }
00390 
00391 void CellFormat::createFontCombo(QComboBox *combo)
00392 {
00393     combo->insertStringList(fontDB.families());
00394 }
00395 
00396 void CellFormat::createStyleCombo(QComboBox *combo)
00397 {
00398     int width=combo->listBox()->maxItemWidth();
00399     QPixmap pix(width, COMBO_HEIGHTS);
00400     QPainter p(&pix);
00401 
00402     for (int i=0; i<STYLE_COUNT; ++i)
00403     {
00404         pix.fill();
00405         p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]);
00406         combo->insertItem(pix);
00407     }
00408 }
00409 
00410 void CellFormat::createColorCombo(QComboBox *combo)
00411 {
00412     int width=combo->listBox()->maxItemWidth();
00413     QPixmap pix(width, COMBO_HEIGHTS);
00414     QPainter p(&pix);
00415 
00416     for (int i=0; i<COLOR_COUNT; ++i)
00417     {
00418         pix.fill();
00419         p.setPen(QPen(qtColors[i], 3, Qt::SolidLine));
00420         p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
00421         combo->insertItem(pix);
00422     }
00423 }
00424 
00425 int CellFormat::exec(Sheet *s)
00426 {
00427     sheet=s;
00428     int row1, row2, col1, col2, row, col;
00429     sheet->getSelection(&row1, &col1, &row2, &col2);
00430 
00431     QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0),
00432                 penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1),
00433                         penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0),
00434                                 penDefault=borderEditor->getDefaultPen();
00435     for (row=row1+1; row<=row2; ++row)
00436         if (sheet->getPen(row, col1-1, 1)!=penLeft)
00437         {
00438             penLeft=penDefault;
00439             break;
00440         }
00441     for (row=row1+1; row<=row2; ++row)
00442         if (sheet->getPen(row, col2, 1)!=penRight)
00443         {
00444             penRight=penDefault;
00445             break;
00446         }
00447     for (col=col1+1; col<=col2; ++col)
00448         if (sheet->getPen(row1-1, col, 0)!=penTop)
00449         {
00450             penTop=penDefault;
00451             break;
00452         }
00453     for (col=col1+1; col<=col2; ++col)
00454         if (sheet->getPen(row2, col, 0)!=penBottom)
00455         {
00456             penBottom=penDefault;
00457             break;
00458         }
00459     for (row=row1; row<=row2; ++row)
00460         for (col=col1; col<col2; ++col)
00461             if (sheet->getPen(row, col, 1)!=penVert)
00462             {
00463                 penVert=penDefault;
00464                 break;
00465             }
00466     for (row=row1; row<row2; ++row)
00467         for (col=col1; col<=col2; ++col)
00468             if (sheet->getPen(row, col, 0)!=penHorz)
00469             {
00470                 penHorz=penDefault;
00471                 break;
00472             }
00473 
00474     borderEditor->setPen(penTop, BorderEditor::Top);
00475     borderEditor->setPen(penBottom, BorderEditor::Bottom);
00476     borderEditor->setPen(penLeft, BorderEditor::Left);
00477     borderEditor->setPen(penRight, BorderEditor::Right);
00478     borderEditor->setPen(penVert, BorderEditor::Vert);
00479     borderEditor->setPen(penHorz, BorderEditor::Horz);
00480 
00481     setBrushBackground(sheet->getBrush(row1, col1));
00482     setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1));
00483     setTextAlign(sheet->getAlignment(row1, col1));
00484 
00485     if (QDialog::exec()==QDialog::Accepted)
00486     {
00487         penTop=borderEditor->getPen(BorderEditor::Top);
00488         penBottom=borderEditor->getPen(BorderEditor::Bottom);
00489         penLeft=borderEditor->getPen(BorderEditor::Left);
00490         penRight=borderEditor->getPen(BorderEditor::Right);
00491         penVert=borderEditor->getPen(BorderEditor::Vert);
00492         penHorz=borderEditor->getPen(BorderEditor::Horz);
00493 
00494         if (penTop!=penDefault)
00495             for (col=col1; col<=col2; ++col)
00496                 sheet->setPen(row1-1, col, 0, penTop);
00497         if (penBottom!=penDefault)
00498             for (col=col1; col<=col2; ++col)
00499                 sheet->setPen(row2, col, 0, penBottom);
00500         if (penLeft!=penDefault)
00501             for (row=row1; row<=row2; ++row)
00502                 sheet->setPen(row, col1-1, 1, penLeft);
00503         if (penRight!=penDefault)
00504             for (row=row1; row<=row2; ++row)
00505                 sheet->setPen(row, col2, 1, penRight);
00506         if (penVert!=penDefault)
00507             for (row=row1; row<=row2; ++row)
00508                 for (col=col1; col<col2; ++col)
00509                     sheet->setPen(row, col, 1, penVert);
00510         if (penHorz!=penDefault)
00511             for (row=row1; row<row2; ++row)
00512                 for (col=col1; col<=col2; ++col)
00513                     sheet->setPen(row, col, 0, penHorz);
00514 
00515         if (changedBrush)
00516         {
00517             for (row=row1; row<=row2; ++row)
00518                 for (col=col1; col<=col2; ++col)
00519                     sheet->setBrush(row, col, brushBackground);
00520         }
00521 
00522         if (changedAlign)
00523         {
00524             for (row=row1; row<=row2; ++row)
00525                 for (col=col1; col<=col2; ++col)
00526                     sheet->setTextAlign(row, col, textAlignment);
00527         }
00528 
00529         if (changedFont)
00530         {
00531             for (row=row1; row<=row2; ++row)
00532                 for (col=col1; col<=col2; ++col)
00533                     sheet->setTextFont(row, col, fontFont, fontColor);
00534         }
00535         return QDialog::Accepted;
00536     }
00537     return QDialog::Rejected;
00538 }
00539 
00540 //
00541 // Border Editor
00542 //
00543 
00544 BorderEditor::BorderEditor(QWidget *parent)
00545         :QFrame(parent)
00546 {
00547     setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00548 }
00549 
00550 BorderEditor::~BorderEditor()
00551 {}
00552 
00553 void BorderEditor::drawContents(QPainter *p)
00554 {
00555     QFrame::drawContents(p);
00556 
00557     int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
00558     int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6;
00559 
00560     p->fillRect(contentsRect(), Qt::white);
00561 
00562     p->fillRect(x+width/3, y+height/3, width, height, Qt::gray);
00563     p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray);
00564     p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray);
00565     p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray);
00566 
00567     if (penTop.width()>0)
00568     {
00569         p->setPen(penTop);
00570         p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY);
00571     }
00572     if (penBottom.width()>0)
00573     {
00574         p->setPen(penBottom);
00575         p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY);
00576     }
00577     if (penHorz.width()>0)
00578     {
00579         p->setPen(penHorz);
00580         p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2);
00581     }
00582     if (penLeft.width()>0)
00583     {
00584         p->setPen(penLeft);
00585         p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY);
00586     }
00587     if (penRight.width()>0)
00588     {
00589         p->setPen(penRight);
00590         p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY);
00591     }
00592     if (penVert.width()>0)
00593     {
00594         p->setPen(penVert);
00595         p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY);
00596     }
00597 }
00598 
00599 void BorderEditor::setPen(const QPen &pen, BorderArea area)
00600 {
00601     switch (area)
00602     {
00603     case Top: penTop=pen; break;
00604     case Bottom: penBottom=pen; break;
00605     case Left: penLeft=pen; break;
00606     case Right: penRight=pen; break;
00607     case Horz: penHorz=pen; break;
00608     case Vert: penVert=pen; break;
00609     };
00610     update();
00611 }
00612 
00613 void BorderEditor::mouseReleaseEvent(QMouseEvent *e)
00614 {
00615     QFrame::mouseReleaseEvent(e);
00616 
00617     int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
00618     BorderArea area=None;
00619 
00620     if (e->x()<x+width/3) area=Left;
00621     if (e->x()>x+(8*width)/3) area=Right;
00622     if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert;
00623 
00624     if (e->y()<y+height/3) area=Top;
00625     if (e->y()>y+(8*height)/3) area=Bottom;
00626     if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz;
00627 
00628     if (area!=None)
00629         emit clicked(area);
00630 }
00631 
00632 QPen BorderEditor::getPen(BorderArea area)
00633 {
00634     switch (area)
00635     {
00636     case Top: return penTop;
00637     case Bottom: return penBottom;
00638     case Left: return penLeft;
00639     case Right: return penRight;
00640     case Horz: return penHorz;
00641     case Vert: return penVert;
00642     };
00643     return getDefaultPen();
00644 }

Generated on Sat Nov 5 16:17:00 2005 for OPIE by  doxygen 1.4.2