Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XABPriorityCtrl: Priority control implemented
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 28 Aug 2017 17:21:06 +0000 (18:21 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 28 Aug 2017 17:21:06 +0000 (18:21 +0100)
source/widgets/XABPriorityCtrl.cpp [new file with mode: 0644]
source/widgets/XABPriorityCtrl.h [new file with mode: 0644]

diff --git a/source/widgets/XABPriorityCtrl.cpp b/source/widgets/XABPriorityCtrl.cpp
new file mode 100644 (file)
index 0000000..23e68af
--- /dev/null
@@ -0,0 +1,138 @@
+// XABPriorityCtrl.cpp - XABPriorityCtrl widget
+//
+// (c) 2017 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
+#include "XABPriorityCtrl.h"
+
+XABPriorityCtrl::XABPriorityCtrl(wxWindow *parent) : 
+       wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, "")
+{
+       parentControl = parent;
+
+       // Setup the sizers.
+       mainSizer = new wxFlexGridSizer(2, 3, 0, 0);
+       sliderSizer = new wxFlexGridSizer(2, 1, 0, 0);
+       sliderLabelSizer = new wxBoxSizer(wxHORIZONTAL);
+       
+       mainSizer->AddGrowableCol(2);
+       
+       // Setup the controls.
+       chkPriority = new wxCheckBox(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0);
+       txtPriority = new wxTextCtrl(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxTextCtrlNameStr);
+       sliPriority = new wxSlider(this, wxID_ANY, 0, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
+       highLabel = new wxStaticText(this, wxID_ANY, _("High"), wxDefaultPosition, wxDefaultSize, 0);
+       lowLabel = new wxStaticText(this, wxID_ANY, _("Low"), wxDefaultPosition, wxDefaultSize, 0);
+       
+       // Attach the controls.
+       mainSizer->Add(chkPriority, 0, wxALL, 5);
+       mainSizer->Add(txtPriority, 0, wxALL, 5);
+       mainSizer->Add(sliPriority, 1, wxEXPAND, 5);
+       
+       /*sliderSizer->Add(sliPriority, 1, wxEXPAND, 5);*/
+
+       sliderLabelSizer->Add(highLabel, 1, wxALIGN_LEFT, 5);   
+       sliderLabelSizer->Add(0, 1, wxEXPAND, 5);
+       sliderLabelSizer->Add(lowLabel, 1, wxALIGN_RIGHT, 5);
+
+       mainSizer->Add(0, 0, 0, 5);
+       mainSizer->Add(0, 0, 0, 5);
+       mainSizer->Add(sliderLabelSizer, 1, wxEXPAND, 5);
+
+       txtPriority->SetMaxLength(3);
+
+       // Disable the text, slider and static text controls by default.
+       txtPriority->Enable(false);
+       sliPriority->Enable(false);
+       highLabel->Enable(false);
+       lowLabel->Enable(false);
+       
+       // Set the main sizer for the control.
+       this->SetSizer(mainSizer);
+       
+       Connect(wxEVT_SLIDER, wxCommandEventHandler(XABPriorityCtrl::SliderEvent), NULL, this );
+       Connect(wxEVT_CHECKBOX, wxCommandEventHandler(XABPriorityCtrl::EnableControls), NULL, this);
+       Connect(wxEVT_TEXT, wxCommandEventHandler(XABPriorityCtrl::TextEvent), NULL, this);
+}
+
+XABPriorityCtrl::~XABPriorityCtrl()
+{
+}
+
+void XABPriorityCtrl::EnableControls(wxCommandEvent &event)
+{
+       EnablePriority(chkPriority->IsChecked());
+}
+
+void XABPriorityCtrl::SliderEvent(wxCommandEvent &event)
+{
+       UpdateTextValue();
+}
+
+void XABPriorityCtrl::TextEvent(wxCommandEvent &event)
+{
+       long value;
+       if (txtPriority->GetValue().ToLong(&value))
+       {
+               sliPriority->SetValue(value);
+       }
+}
+
+void XABPriorityCtrl::EnablePriority(bool enable)
+{
+       if (enable)
+       {
+               chkPriority->SetValue(true);
+               txtPriority->Enable(true);
+               sliPriority->Enable(true);
+               highLabel->Enable(true);
+               lowLabel->Enable(true);
+       }
+       else
+       {
+               chkPriority->SetValue(false);
+               txtPriority->Enable(false);
+               sliPriority->Enable(false);
+               highLabel->Enable(false);
+               lowLabel->Enable(false);
+       }
+}
+
+void XABPriorityCtrl::UpdateTextValue()
+{
+       txtPriority->SetValue(wxString::Format("%i", sliPriority->GetValue()));
+}
+
+void XABPriorityCtrl::UpdateSlider(int value)
+{
+       sliPriority->SetValue(value);
+}
+
+bool XABPriorityCtrl::IsPriorityChecked()
+{
+       return chkPriority->IsChecked();
+}
+
+int XABPriorityCtrl::GetValue()
+{
+       return sliPriority->GetValue();
+}
+
+void XABPriorityCtrl::SetValue(int value)
+{
+       sliPriority->SetValue(value);
+       txtPriority->SetValue(wxString::Format("%i", value));
+}
\ No newline at end of file
diff --git a/source/widgets/XABPriorityCtrl.h b/source/widgets/XABPriorityCtrl.h
new file mode 100644 (file)
index 0000000..b14223a
--- /dev/null
@@ -0,0 +1,53 @@
+// XABPriorityCtrl.h - XABPriorityCtrl widget header
+//
+// (c) 2017 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
+#ifndef __WIDGETS_XABPRIORITYCTRL_H__
+#define __WIDGETS_XABPRIORITYCTRL_H__
+
+#include <wx/wx.h>
+
+class XABPriorityCtrl : public wxPanel
+{
+       private:
+               wxWindow *parentControl = nullptr;
+       
+               wxFlexGridSizer *mainSizer = nullptr;
+               wxFlexGridSizer *sliderSizer = nullptr;
+               wxBoxSizer *sliderLabelSizer = nullptr;
+               wxCheckBox *chkPriority = nullptr;
+               wxTextCtrl *txtPriority = nullptr;
+               wxSlider *sliPriority = nullptr;
+               wxStaticText *lowLabel = nullptr;
+               wxStaticText *highLabel = nullptr;
+       protected:
+               void UpdateTextValue();
+               void UpdateSlider(int value);
+               void SliderEvent(wxCommandEvent &event);
+               void TextEvent(wxCommandEvent &event);
+               void EnableControls(wxCommandEvent &event);
+       public:
+               XABPriorityCtrl(wxWindow *parent);
+               ~XABPriorityCtrl();
+               void EnablePriority(bool enable);
+               bool IsPriorityChecked();
+               int GetValue();
+               void SetValue(int value);
+};
+
+
+#endif
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