00001
00007 #include "HBFormatPanel.h"
00008 #include <QtGui/QFontDialog>
00009 #include <QtGui/QPalette>
00010 #include <QtGui/QColorDialog>
00011
00012 HBFormatPanel::HBFormatPanel(QWidget * parent,HighlightBlock * _block): QGroupBox(parent)
00013 {
00014 block=_block;
00015 this->setTitle("Font and colors settings");
00016 mainLayout=new QVBoxLayout(this);
00017 editFontButton=new QPushButton("Change Font");
00018 fontSample=new QLabel("Sample formatted text");
00019 updateSample();
00020 mainLayout->addWidget(fontSample);
00021
00022 buttonsLayout=new QHBoxLayout();
00023 editFontButton=new QPushButton("Change Font Style");;
00024 editFColorButton=new QPushButton("Change Foreground Color");
00025 editBColorButton=new QPushButton("Change Background Color");
00026
00027 buttonsLayout->addWidget(editFontButton);
00028 buttonsLayout->addWidget(editFColorButton);
00029 buttonsLayout->addWidget(editBColorButton);
00030
00031 mainLayout->addLayout(buttonsLayout);
00032 connect(editFontButton,SIGNAL(clicked()),this,SLOT(showFontDialog()));
00033 connect(editFColorButton,SIGNAL(clicked()),this,SLOT(showFColorDialog()));
00034 connect(editBColorButton,SIGNAL(clicked()),this,SLOT(showBColorDialog()));
00035 };
00036 void HBFormatPanel::updateSample()
00037 {
00038 fontSample->setFont(block->getFont());
00039 QPalette temp=fontSample->palette();
00040 temp.setColor(QPalette::WindowText,block->getForegroundColor());
00041 temp.setColor(fontSample->backgroundRole(),block->getBackgroundColor());
00042 fontSample->setPalette(temp);
00043 fontSample->setAutoFillBackground(true);
00044 }
00045 void HBFormatPanel::showFontDialog()
00046 {
00047 bool ok;
00048 block->setFont(QFontDialog::getFont(&ok,block->getFont(),this));
00049 if(ok)
00050 updateSample();
00051
00052 }
00053 void HBFormatPanel::showFColorDialog()
00054 {
00055 block->setForegroundColor(QColorDialog::getColor(block->getForegroundColor(),this));
00056 updateSample();
00057 }
00058 void HBFormatPanel::showBColorDialog()
00059 {
00060 block->setBackgroundColor(QColorDialog::getColor(block->getBackgroundColor(),this));
00061 updateSample();
00062 }