From 21bb5bd2bd4243dc83a08d6e0329b5de2f96b1fe Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 3 Oct 2015 14:34:20 +0200 Subject: Refactor ComboBox and ListBox(Thin and Basic). --- plugingui/listbox.cc | 116 ++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 57 deletions(-) (limited to 'plugingui/listbox.cc') diff --git a/plugingui/listbox.cc b/plugingui/listbox.cc index ed873b2..22263b0 100644 --- a/plugingui/listbox.cc +++ b/plugingui/listbox.cc @@ -29,95 +29,97 @@ #include "painter.h" #include "font.h" -#include - -GUI::ListBox::ListBox(GUI::Widget *parent) - : GUI::Widget(parent) +namespace GUI { + +ListBox::ListBox(Widget *parent) + : Widget(parent) + , selectionNotifier(basic.selectionNotifier) + , clickNotifier(basic.clickNotifier) + , valueChangedNotifier(basic.valueChangedNotifier) + , basic(this) { - box.topLeft = new Image(":widget_tl.png"); - box.top = new Image(":widget_t.png"); - box.topRight = new Image(":widget_tr.png"); - box.left = new Image(":widget_l.png"); - box.right = new Image(":widget_r.png"); - box.bottomLeft = new Image(":widget_bl.png"); - box.bottom = new Image(":widget_b.png"); - box.bottomRight = new Image(":widget_br.png"); - box.center = new Image(":widget_c.png"); - - basic = new GUI::ListBoxBasic(this); - basic->move(box.left->width(), box.top->height()); + box.topLeft = new Image(":widget_tl.png"); + box.top = new Image(":widget_t.png"); + box.topRight = new Image(":widget_tr.png"); + box.left = new Image(":widget_l.png"); + box.right = new Image(":widget_r.png"); + box.bottomLeft = new Image(":widget_bl.png"); + box.bottom = new Image(":widget_b.png"); + box.bottomRight = new Image(":widget_br.png"); + box.center = new Image(":widget_c.png"); + + basic.move(box.left->width(), box.top->height()); } -GUI::ListBox::~ListBox() +ListBox::~ListBox() { + delete box.topLeft; + delete box.top; + delete box.topRight; + delete box.left; + delete box.right; + delete box.bottomLeft; + delete box.bottom; + delete box.bottomRight; + delete box.center; } -void GUI::ListBox::addItem(std::string name, std::string value) +void ListBox::addItem(std::string name, std::string value) { - basic->addItem(name, value); + basic.addItem(name, value); } -void GUI::ListBox::addItems(std::vector &items) +void ListBox::addItems(std::vector &items) { - basic->addItems(items); + basic.addItems(items); } -void GUI::ListBox::clear() +void ListBox::clear() { - basic->clear(); + basic.clear(); } -bool GUI::ListBox::selectItem(int index) +bool ListBox::selectItem(int index) { - return basic->selectItem(index); + return basic.selectItem(index); } -std::string GUI::ListBox::selectedName() +std::string ListBox::selectedName() { - return basic->selectedName(); + return basic.selectedName(); } -std::string GUI::ListBox::selectedValue() +std::string ListBox::selectedValue() { - return basic->selectedValue(); + return basic.selectedValue(); } -void GUI::ListBox::clearSelectedValue() +void ListBox::clearSelectedValue() { - basic->clearSelectedValue(); + basic.clearSelectedValue(); } -void GUI::ListBox::registerClickHandler(void (*handler)(void *), void *ptr) +void ListBox::repaintEvent(RepaintEvent *e) { - basic->registerClickHandler(handler, ptr); -} + Painter p(this); -void GUI::ListBox::registerSelectHandler(void (*handler)(void *), void *ptr) -{ - basic->registerSelectHandler(handler, ptr); -} + p.clear(); -void GUI::ListBox::registerValueChangeHandler(void (*handler)(void *), - void *ptr) -{ - basic->registerValueChangeHandler(handler, ptr); -} + int w = width(); + int h = height(); + if(w == 0 || h == 0) + { + return; + } -void GUI::ListBox::repaintEvent(GUI::RepaintEvent *e) -{ - GUI::Painter p(this); - - p.clear(); - - int w = width(); - int h = height(); - if(w == 0 || h == 0) return; - p.drawBox(0, 0, &box, w, h); + p.drawBox(0, 0, &box, w, h); } -void GUI::ListBox::resize(int width, int height) +void ListBox::resize(int width, int height) { - GUI::Widget::resize(width, height); - basic->resize(width - (box.left->width() + box.right->width()), - height - (box.top->height() + box.bottom->height())); + Widget::resize(width, height); + basic.resize(width - (box.left->width() + box.right->width()), + height - (box.top->height() + box.bottom->height())); } + +} // GUI:: -- cgit v1.2.3