1
/***************************************************************************
2
rkdropdown.h - description
4
begin : Fri Jan 12 2007
5
copyright : (C) 2007 by Thomas Friedrichsmeier
6
email : tfry@users.sourceforge.net
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "rkdropdown.h"
23
#include <qcombobox.h>
28
#include "../rkglobals.h"
29
#include "../misc/xmlhelper.h"
32
RKDropDown::RKDropDown (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKAbstractOptionSelector (parent_component, parent_widget) {
36
XMLHelper *xml = XMLHelper::getStaticHelper ();
39
QVBoxLayout *vbox = new QVBoxLayout (this, RKGlobals::spacingHint ());
41
QLabel *label = new QLabel (xml->getStringAttribute (element, "label", i18n ("Select one:"), DL_INFO), this);
42
vbox->addWidget (label);
45
box = new QComboBox (false, this);
46
if (!(box->listBox ())) {
47
// make sure the combo box uses a list box internally
48
box->setListBox (new QListBox (this));
51
addOptionsAndInit (element);
53
vbox->addWidget (box);
54
connect (box, SIGNAL (activated (int)), this, SLOT (comboItemActivated (int)));
57
RKDropDown::~RKDropDown(){
61
void RKDropDown::comboItemActivated (int id) {
64
QListBox *list = box->listBox ();
66
QListBoxItem *item = list->item (id);
68
if (!item->isSelectable ()) return; // yes, apparently not selectable items can be "activated"
73
void RKDropDown::setItemInGUI (int id) {
76
box->setCurrentItem (id);
79
void RKDropDown::addOptionToGUI (const QString &label, int id) {
82
box->insertItem (label, id);
85
void RKDropDown::setItemEnabledInGUI (int id, bool enabled) {
88
QListBox *list = box->listBox ();
90
QListBoxItem *item = list->item (id);
93
if (item->rtti () != ID_RKDROPDOWNLISTITEM) {
94
// this item won't show whether it is enabled or not. We need to replace it.
95
item = new RKDropDownListItem (0, list->text (id));
96
list->changeItem (item, id);
99
item->setSelectable (enabled);
102
////////////////// RKDropDownListItem ////////////////////////
104
#include <qpainter.h>
106
RKDropDownListItem::RKDropDownListItem (QListBox *listbox, const QString &text) : QListBoxText (listbox, text) {
110
void RKDropDownListItem::paint (QPainter *painter) {
112
if (!isSelectable ()) {
113
painter->setPen (QColor (150, 150, 150));
116
QListBoxText::paint (painter);
119
#include "rkdropdown.moc"