Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Ignore build* directories
[xestiaab/.git] / source / widgets / XABPriorityCtrl.cpp
1 // XABPriorityCtrl.cpp - XABPriorityCtrl widget
2 //
3 // (c) 2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "XABPriorityCtrl.h"
21 XABPriorityCtrl::XABPriorityCtrl(wxWindow *parent) : 
22         wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, "")
23 {
24         parentControl = parent;
26         // Setup the sizers.
27         mainSizer = new wxFlexGridSizer(2, 3, 0, 0);
28         sliderSizer = new wxFlexGridSizer(2, 1, 0, 0);
29         sliderLabelSizer = new wxBoxSizer(wxHORIZONTAL);
30         
31         mainSizer->AddGrowableCol(2);
32         
33         // Setup the controls.
34         chkPriority = new wxCheckBox(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0);
35         txtPriority = new wxTextCtrl(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxTextCtrlNameStr);
36         sliPriority = new wxSlider(this, wxID_ANY, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
37         highLabel = new wxStaticText(this, wxID_ANY, _("High"), wxDefaultPosition, wxDefaultSize, 0);
38         lowLabel = new wxStaticText(this, wxID_ANY, _("Low"), wxDefaultPosition, wxDefaultSize, 0);
39         
40         // Attach the controls.
41         mainSizer->Add(chkPriority, 0, wxALL, 5);
42         mainSizer->Add(txtPriority, 0, wxALL, 5);
43         mainSizer->Add(sliPriority, 1, wxEXPAND, 5);
44         
45         /*sliderSizer->Add(sliPriority, 1, wxEXPAND, 5);*/
47         sliderLabelSizer->Add(highLabel, 1, wxALIGN_LEFT, 5);   
48         sliderLabelSizer->Add(0, 1, wxEXPAND, 5);
49         sliderLabelSizer->Add(lowLabel, 1, wxALIGN_RIGHT, 5);
51         mainSizer->Add(0, 0, 0, 5);
52         mainSizer->Add(0, 0, 0, 5);
53         mainSizer->Add(sliderLabelSizer, 1, wxEXPAND, 5);
55         txtPriority->SetMaxLength(3);
57         // Disable the text, slider and static text controls by default.
58         txtPriority->Enable(false);
59         sliPriority->Enable(false);
60         highLabel->Enable(false);
61         lowLabel->Enable(false);
62         
63         // Set the main sizer for the control.
64         this->SetSizer(mainSizer);
65         
66         Connect(wxEVT_SLIDER, wxCommandEventHandler(XABPriorityCtrl::SliderEvent), NULL, this );
67         Connect(wxEVT_CHECKBOX, wxCommandEventHandler(XABPriorityCtrl::EnableControls), NULL, this);
68         Connect(wxEVT_TEXT, wxCommandEventHandler(XABPriorityCtrl::TextEvent), NULL, this);
69 }
71 XABPriorityCtrl::~XABPriorityCtrl()
72 {
73 }
75 void XABPriorityCtrl::EnableControls(wxCommandEvent &event)
76 {
77         EnablePriority(chkPriority->IsChecked());
78 }
80 void XABPriorityCtrl::SliderEvent(wxCommandEvent &event)
81 {
82         UpdateTextValue();
83 }
85 void XABPriorityCtrl::TextEvent(wxCommandEvent &event)
86 {
87         long value;
88         if (txtPriority->GetValue().ToLong(&value))
89         {
90                 sliPriority->SetValue(value);
91         }
92 }
94 void XABPriorityCtrl::EnablePriority(bool enable)
95 {
96         if (enable)
97         {
98                 chkPriority->SetValue(true);
99                 txtPriority->Enable(true);
100                 sliPriority->Enable(true);
101                 highLabel->Enable(true);
102                 lowLabel->Enable(true);
103         }
104         else
105         {
106                 chkPriority->SetValue(false);
107                 txtPriority->Enable(false);
108                 sliPriority->Enable(false);
109                 highLabel->Enable(false);
110                 lowLabel->Enable(false);
111         }
114 void XABPriorityCtrl::UpdateTextValue()
116         txtPriority->SetValue(wxString::Format("%i", sliPriority->GetValue()));
119 void XABPriorityCtrl::UpdateSlider(int value)
121         sliPriority->SetValue(value);
124 bool XABPriorityCtrl::IsPriorityChecked()
126         return chkPriority->IsChecked();
129 int XABPriorityCtrl::GetValue()
131         return sliPriority->GetValue();
134 void XABPriorityCtrl::SetValue(int value)
136         sliPriority->SetValue(value);
137         txtPriority->SetValue(wxString::Format("%i", value));
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy