Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Widget {
- private:
- unsigned int h,w;
- bool visible;
- public:
- virtual void setStandardSize() =0;
- Widget(unsigned int height=0, unsigned int width=0, bool vis =true):
- h(height), w(width), visible(vis) {}
- virtual ~Widget() =default;
- void setHeight(unsigned int height) {h=height;}
- void setWidth(unsigned int width) {w=width;}
- };
- #include<string>
- class AbstractButton: public Widget {
- private:
- std::string label;
- public:
- AbstractButton(unsigned int height=0, unsigned int width=0, bool vis =true,
- const std::string& l=""): Widget(height,width,vis), label(l) {}
- std::string getLabel() const {return label;}
- };
- class PushButton: public AbstractButton {
- public:
- static const unsigned int standardHeight = 80;
- static const unsigned int standardWidth = 20;
- void setStandardSize() override {
- setHeight(standardHeight); setWidth(standardWidth);
- }
- PushButton(unsigned int height=standardHeight, unsigned int width= standardWidth,
- bool vis =true, const std::string& l=""): AbstractButton(height,width,vis,l) {}
- };
- class CheckBox: public AbstractButton {
- private:
- bool checked;
- public:
- static const unsigned int standardHeight = 5;
- static const unsigned int standardWidth = 5;
- void setStandardSize() override {
- setHeight(standardHeight); setWidth(standardWidth);
- }
- CheckBox(unsigned int height=standardHeight, unsigned int width= standardWidth,
- const std::string& l="", bool check=false):
- AbstractButton(height,width,true,l), checked(check) {}
- bool isChecked() const {return checked;}
- };
- #include<vector>
- #include<list>
- class Gui {
- private:
- std::vector<const Widget*> NoButtons;
- std::list<const AbstractButton*> Buttons;
- public:
- void insert(Widget* pw) {
- if(pw == nullptr) throw std::string("NoInsert");
- if(dynamic_cast<AbstractButton*>(pw) != nullptr)
- Buttons.push_back(static_cast<AbstractButton*>(pw));
- else NoButtons.push_back(pw);
- }
- void insert(unsigned int pos, PushButton& pb) {
- if(pos > Buttons.size()) throw std::string("NoInsert");
- auto it = Buttons.begin();
- for( ; pos>0; pos--, it++);
- Buttons.insert(it, &pb);
- }
- std::vector<AbstractButton*> removeUnchecked() {
- std::vector<AbstractButton*> v;
- CheckBox* p;
- for(auto it=Buttons.begin(); it!=Buttons.end(); ++it) {
- p=const_cast<CheckBox*>(dynamic_cast<const CheckBox*>(*it));
- if(p && !(p->isChecked())) {
- v.push_back(p);
- it=Buttons.erase(it); --it;
- }
- }
- return v;
- }
- void setStandardPushButton() {
- for(auto it = Buttons.begin(); it != Buttons.end(); ++it)
- if(dynamic_cast<const PushButton*>(*it) != nullptr && !((*it)->getLabel().empty()))
- (const_cast<AbstractButton*>(*it))->setStandardSize();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment