~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/plugin/rkdropdown.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2008-04-20 21:30:00 UTC
  • mfrom: (1.2.2 upstream) (3.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080420213000-fs4i8efmfc793bnn
new upstream release
closes: #475175
closes: #463348
closes: #475982

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          rkdropdown.h  -  description
 
3
                             -------------------
 
4
    begin                : Fri Jan 12 2007
 
5
    copyright            : (C) 2007 by Thomas Friedrichsmeier
 
6
    email                : tfry@users.sourceforge.net
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "rkdropdown.h"
 
19
 
 
20
#include <qdom.h>
 
21
#include <qlabel.h>
 
22
#include <qlayout.h>
 
23
#include <qcombobox.h>
 
24
#include <qlistbox.h>
 
25
 
 
26
#include <klocale.h>
 
27
 
 
28
#include "../rkglobals.h"
 
29
#include "../misc/xmlhelper.h"
 
30
#include "../debug.h"
 
31
 
 
32
RKDropDown::RKDropDown (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKAbstractOptionSelector (parent_component, parent_widget) {
 
33
        RK_TRACE (PLUGIN);
 
34
 
 
35
        // get xml-helper
 
36
        XMLHelper *xml = XMLHelper::getStaticHelper ();
 
37
 
 
38
        // create layout
 
39
        QVBoxLayout *vbox = new QVBoxLayout (this, RKGlobals::spacingHint ());
 
40
 
 
41
        QLabel *label = new QLabel (xml->getStringAttribute (element, "label", i18n ("Select one:"), DL_INFO), this);
 
42
        vbox->addWidget (label);
 
43
 
 
44
        // create ComboBox
 
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));
 
49
        }
 
50
 
 
51
        addOptionsAndInit (element);
 
52
 
 
53
        vbox->addWidget (box);
 
54
        connect (box, SIGNAL (activated (int)), this, SLOT (comboItemActivated (int)));
 
55
}
 
56
 
 
57
RKDropDown::~RKDropDown(){
 
58
        RK_TRACE (PLUGIN);
 
59
}
 
60
 
 
61
void RKDropDown::comboItemActivated (int id) {
 
62
        RK_TRACE (PLUGIN);
 
63
 
 
64
        QListBox *list = box->listBox ();
 
65
        RK_ASSERT (list);
 
66
        QListBoxItem *item = list->item (id);
 
67
        RK_ASSERT (item);
 
68
        if (!item->isSelectable ()) return;             // yes, apparently not selectable items can be "activated"
 
69
 
 
70
        itemSelected (id);
 
71
}
 
72
 
 
73
void RKDropDown::setItemInGUI (int id) {
 
74
        RK_TRACE (PLUGIN);
 
75
 
 
76
        box->setCurrentItem (id);
 
77
}
 
78
 
 
79
void RKDropDown::addOptionToGUI (const QString &label, int id) {
 
80
        RK_TRACE (PLUGIN);
 
81
 
 
82
        box->insertItem (label, id);
 
83
}
 
84
 
 
85
void RKDropDown::setItemEnabledInGUI (int id, bool enabled) {
 
86
        RK_TRACE (PLUGIN);
 
87
 
 
88
        QListBox *list = box->listBox ();
 
89
        RK_ASSERT (list);
 
90
        QListBoxItem *item = list->item (id);
 
91
        RK_ASSERT (item);
 
92
 
 
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);
 
97
        }
 
98
 
 
99
        item->setSelectable (enabled);
 
100
}
 
101
 
 
102
////////////////// RKDropDownListItem ////////////////////////
 
103
 
 
104
#include <qpainter.h>
 
105
 
 
106
RKDropDownListItem::RKDropDownListItem (QListBox *listbox, const QString &text) : QListBoxText (listbox, text) {
 
107
        RK_TRACE (PLUGIN);
 
108
}
 
109
 
 
110
void RKDropDownListItem::paint (QPainter *painter) {
 
111
        // no trace!
 
112
        if (!isSelectable ()) {
 
113
                painter->setPen (QColor (150, 150, 150));
 
114
        }
 
115
 
 
116
        QListBoxText::paint (painter);
 
117
}
 
118
 
 
119
#include "rkdropdown.moc"