Plasma
scrollbar.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org> 00003 * Copyright © 2008 Marco Martin <notmart@gmail.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Library General Public License as 00007 * published by the Free Software Foundation; either version 2, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details 00014 * 00015 * You should have received a copy of the GNU Library General Public 00016 * License along with this program; if not, write to the 00017 * Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "scrollbar.h" 00022 00023 #include <QApplication> 00024 #include <QContextMenuEvent> 00025 #include <QGraphicsSceneContextMenuEvent> 00026 00027 #include <plasma/private/style_p.h> 00028 00029 namespace Plasma 00030 { 00031 00032 class ScrollBarPrivate 00033 { 00034 public: 00035 Plasma::Style::Ptr style; 00036 }; 00037 00038 ScrollBar::ScrollBar(QGraphicsWidget *parent) 00039 : QGraphicsProxyWidget(parent), 00040 d(new ScrollBarPrivate) 00041 { 00042 QScrollBar *scrollbar = new QScrollBar(); 00043 scrollbar->setWindowFlags(scrollbar->windowFlags()|Qt::BypassGraphicsProxyWidget); 00044 scrollbar->setAttribute(Qt::WA_NoSystemBackground); 00045 setWidget(scrollbar); 00046 scrollbar->setWindowIcon(QIcon()); 00047 d->style = Plasma::Style::sharedStyle(); 00048 scrollbar->setStyle(d->style.data()); 00049 00050 scrollbar->resize(scrollbar->sizeHint()); 00051 connect(scrollbar, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); 00052 connect(scrollbar, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int))); 00053 } 00054 00055 ScrollBar::~ScrollBar() 00056 { 00057 delete d; 00058 Plasma::Style::doneWithSharedStyle(); 00059 } 00060 00061 void ScrollBar::setRange(int min, int max) 00062 { 00063 static_cast<QScrollBar*>(widget())->setRange(min, max); 00064 } 00065 00066 void ScrollBar::setSingleStep(int val) 00067 { 00068 static_cast<QScrollBar*>(widget())->setSingleStep(val); 00069 } 00070 00071 int ScrollBar::singleStep() 00072 { 00073 return static_cast<QScrollBar*>(widget())->singleStep(); 00074 } 00075 00076 void ScrollBar::setPageStep(int val) 00077 { 00078 static_cast<QScrollBar*>(widget())->setPageStep(val); 00079 } 00080 00081 int ScrollBar::pageStep() 00082 { 00083 return static_cast<QScrollBar*>(widget())->pageStep(); 00084 } 00085 00086 void ScrollBar::setValue(int val) 00087 { 00088 static_cast<QScrollBar*>(widget())->setValue(val); 00089 } 00090 00091 int ScrollBar::value() const 00092 { 00093 return static_cast<QScrollBar*>(widget())->value(); 00094 } 00095 00096 int ScrollBar::minimum() const 00097 { 00098 return static_cast<QScrollBar*>(widget())->minimum(); 00099 } 00100 00101 int ScrollBar::maximum() const 00102 { 00103 return static_cast<QScrollBar*>(widget())->maximum(); 00104 } 00105 00106 void ScrollBar::setMinimum(const int min) const 00107 { 00108 static_cast<QScrollBar*>(widget())->setMinimum(min); 00109 } 00110 00111 void ScrollBar::setMaximum(const int max) const 00112 { 00113 static_cast<QScrollBar*>(widget())->setMaximum(max); 00114 } 00115 00116 void ScrollBar::setStyleSheet(const QString &stylesheet) 00117 { 00118 widget()->setStyleSheet(stylesheet); 00119 } 00120 00121 QString ScrollBar::styleSheet() 00122 { 00123 return widget()->styleSheet(); 00124 } 00125 00126 QScrollBar *ScrollBar::nativeWidget() const 00127 { 00128 return static_cast<QScrollBar *>(widget()); 00129 } 00130 00131 Qt::Orientation ScrollBar::orientation() const 00132 { 00133 return nativeWidget()->orientation(); 00134 } 00135 00136 void ScrollBar::setOrientation(Qt::Orientation orientation) 00137 { 00138 QScrollBar *native = static_cast<QScrollBar *>(widget()); 00139 native->setOrientation(orientation); 00140 resize(native->sizeHint()); 00141 } 00142 00143 void ScrollBar::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) 00144 { 00145 QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()), 00146 event->pos().toPoint(), event->screenPos(), event->modifiers()); 00147 QApplication::sendEvent(nativeWidget(), &contextMenuEvent); 00148 } 00149 00150 } 00151 00152 #include <scrollbar.moc>
KDE 4.6 API Reference