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