// 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 #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)); }