00001
00002
00003
00004
00005
00006
00007 #include "QCaptionButton.h"
00008
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013
00014
00015
00016
00017 void QCaptionButton::updateCaptionPosition()
00018 {
00019 int TextWidth = (int)(Font->getTextWidth(Caption.c_str()));
00020 if (Width < (TextWidth+10))
00021 Width = TextWidth+10;
00022 CaptionPositionX = (Width-TextWidth)/2;
00023 }
00024
00025
00026 void QCaptionButton::draw( QEvent* e )
00027 {
00028
00029 LookAndFeel->getBackGroundColor()->setAsCurrent();
00030 glBegin(GL_POLYGON);
00031 LookAndFeel->drawRect(0,0,Width,Height);
00032 glEnd();
00033
00034 LookAndFeel->drawBevel(0,0,Width,Height,State);
00035
00036 if (getFocused())
00037 {
00038 LookAndFeel->getHighlightColor()->setAsCurrent();
00039 glBegin(GL_LINE_LOOP);
00040 LookAndFeel->drawRect(1,1,Width-2,Height-2);
00041 glEnd();
00042 }
00043
00044
00045 if (State == bsDown)
00046 glTranslatef(1,1,0);
00047
00048
00049 Font->drawAtPos(Caption.c_str(),CaptionPositionX,1,Font->getLengthForWidth(Caption.c_str(),Width));
00050 }
00051
00052
00053 void QCaptionButton::layout()
00054 {
00055 QButton::layout();
00056 updateCaptionPosition();
00057 }
00058
00059
00060 bool QCaptionButton::canDrag( QEvent* e )
00061 {
00062 return false;
00063 }
00064
00065
00066 bool QCaptionButton::processEvent( QEvent* e )
00067 {
00068 return QButton::processEvent(e);
00069 }
00070
00071
00072 bool QCaptionButton::processMouseOwner( QEvent* e )
00073 {
00074 return QButton::processMouseOwner(e);
00075 }
00076
00077
00078 void QCaptionButton::childrenChanged()
00079 {
00080 }
00081
00082
00083 bool QCaptionButton::canFocus( QEvent* e )
00084 {
00085 return true;
00086 }
00087
00088
00089 void QCaptionButton::Init()
00090 {
00091 QButton::Init();
00092 Font->copyFrom(LookAndFeel->getFont());
00093 Height = 20;
00094 setCaption("Button");
00095 }
00096
00097
00098 void QCaptionButton::CleanUp()
00099 {
00100 QButton::CleanUp();
00101 }
00102
00103
00104 string QCaptionButton::getCaption()
00105 {
00106 return Caption;
00107 }
00108
00109
00110 void QCaptionButton::setCaption( string newValue )
00111 {
00112 Caption = newValue;
00113 updateCaptionPosition();
00114 }
00115
00116
00117 QFont* QCaptionButton::getFont()
00118 {
00119 return Font;
00120 }
00121
00122
00123
00124
00125 void QCaptionButton::print()
00126 {
00127 cout << "Class : QCaptionButton" << endl;
00128 cout << "Caption = " << Caption << endl;
00129 }
00130
00131
00132
00133
00134 QCaptionButton::QCaptionButton( QWidget* aOwner ):QButton(aOwner)
00135 {
00136 Font = new QFont;
00137 Init();
00138 layout();
00139 }
00140
00141
00142
00143
00144 QCaptionButton::~QCaptionButton()
00145 {
00146 delete Font;
00147 CleanUp();
00148 }
00149
00150
00151
00152