1 // XABPriorityCtrl.cpp - XABPriorityCtrl widget
3 // (c) 2017 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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, "")
24 parentControl = parent;
27 mainSizer = new wxFlexGridSizer(2, 3, 0, 0);
28 sliderSizer = new wxFlexGridSizer(2, 1, 0, 0);
29 sliderLabelSizer = new wxBoxSizer(wxHORIZONTAL);
31 mainSizer->AddGrowableCol(2);
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);
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);
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);
63 // Set the main sizer for the control.
64 this->SetSizer(mainSizer);
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);
71 XABPriorityCtrl::~XABPriorityCtrl()
75 void XABPriorityCtrl::EnableControls(wxCommandEvent &event)
77 EnablePriority(chkPriority->IsChecked());
80 void XABPriorityCtrl::SliderEvent(wxCommandEvent &event)
85 void XABPriorityCtrl::TextEvent(wxCommandEvent &event)
88 if (txtPriority->GetValue().ToLong(&value))
90 sliPriority->SetValue(value);
94 void XABPriorityCtrl::EnablePriority(bool enable)
98 chkPriority->SetValue(true);
99 txtPriority->Enable(true);
100 sliPriority->Enable(true);
101 highLabel->Enable(true);
102 lowLabel->Enable(true);
106 chkPriority->SetValue(false);
107 txtPriority->Enable(false);
108 sliPriority->Enable(false);
109 highLabel->Enable(false);
110 lowLabel->Enable(false);
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));