Plasma
spinbox.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "spinbox.h"
00022
00023 #include <QApplication>
00024 #include <QPainter>
00025 #include <knuminput.h>
00026 #include <kmimetype.h>
00027
00028 #include <plasma/theme.h>
00029 #include <plasma/private/style_p.h>
00030
00031 namespace Plasma
00032 {
00033
00034 class SpinBoxPrivate
00035 {
00036 public:
00037 SpinBoxPrivate(SpinBox *spinBox)
00038 : q(spinBox)
00039 {
00040 }
00041
00042 ~SpinBoxPrivate()
00043 {
00044 }
00045
00046 void setPalette()
00047 {
00048 QSpinBox *native = q->nativeWidget();
00049 QColor color = Theme::defaultTheme()->color(Theme::TextColor);
00050 QPalette p = native->palette();
00051
00052 p.setColor(QPalette::Normal, QPalette::Text, color);
00053 p.setColor(QPalette::Inactive, QPalette::Text, color);
00054 p.setColor(QPalette::Normal, QPalette::ButtonText, color);
00055 p.setColor(QPalette::Inactive, QPalette::ButtonText, color);
00056 p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
00057 p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
00058 native->setPalette(p);
00059 native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
00060 }
00061
00062 SpinBox *q;
00063 Plasma::Style::Ptr style;
00064 };
00065
00066 SpinBox::SpinBox(QGraphicsWidget *parent)
00067 : QGraphicsProxyWidget(parent),
00068 d(new SpinBoxPrivate(this))
00069 {
00070 KIntSpinBox *native = new KIntSpinBox;
00071
00072 connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
00073 connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00074
00075 setWidget(native);
00076 native->setAttribute(Qt::WA_NoSystemBackground);
00077 native->setAutoFillBackground(false);
00078
00079 d->style = Plasma::Style::sharedStyle();
00080 native->setStyle(d->style.data());
00081 d->setPalette();
00082 connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
00083 }
00084
00085 SpinBox::~SpinBox()
00086 {
00087 delete d;
00088 Plasma::Style::doneWithSharedStyle();
00089 }
00090
00091 void SpinBox::setMaximum(int max)
00092 {
00093 static_cast<KIntSpinBox*>(widget())->setMaximum(max);
00094 }
00095
00096 int SpinBox::maximum() const
00097 {
00098 return static_cast<KIntSpinBox*>(widget())->maximum();
00099 }
00100
00101 void SpinBox::setMinimum(int min)
00102 {
00103 static_cast<KIntSpinBox*>(widget())->setMinimum(min);
00104 }
00105
00106 int SpinBox::minimum() const
00107 {
00108 return static_cast<KIntSpinBox*>(widget())->minimum();
00109 }
00110
00111 void SpinBox::setRange(int min, int max)
00112 {
00113 static_cast<KIntSpinBox*>(widget())->setRange(min, max);
00114 }
00115
00116 void SpinBox::setValue(int value)
00117 {
00118 static_cast<KIntSpinBox*>(widget())->setValue(value);
00119 }
00120
00121 int SpinBox::value() const
00122 {
00123 return static_cast<KIntSpinBox*>(widget())->value();
00124 }
00125
00126 void SpinBox::setStyleSheet(const QString &stylesheet)
00127 {
00128 widget()->setStyleSheet(stylesheet);
00129 }
00130
00131 QString SpinBox::styleSheet()
00132 {
00133 return widget()->styleSheet();
00134 }
00135
00136 KIntSpinBox *SpinBox::nativeWidget() const
00137 {
00138 return static_cast<KIntSpinBox*>(widget());
00139 }
00140
00141 }
00142
00143 #include <spinbox.moc>
00144