1 /*
2  scope_dialog.cpp     MindForger thinking notebook
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program 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
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "scope_dialog.h"
20 
21 namespace m8r {
22 
ScopeDialog(Ontology & ontology,QWidget * parent)23 ScopeDialog::ScopeDialog(Ontology& ontology, QWidget *parent)
24     : QDialog{parent}, ontology(ontology)
25 {
26     QVBoxLayout* timepointThresholdLayout = new QVBoxLayout{this};
27 
28     // scope by time
29     enableTimeScopeCheck = new QCheckBox{tr("show Notebooks/Notes modified or viewed in recent")+":", this};
30     enableTimeScopeCheck->setChecked(false);
31 
32     QWidget* w = new QWidget(this);
33     QHBoxLayout* spinsLayout = new QHBoxLayout{w}; // layout MUST get widget to CONSTRUCTOR
34     yearSpin = new QSpinBox{this};
35     yearSpin->setEnabled(false);
36     yearSpin->setMinimum(0);
37     yearSpin->setMaximum(50);
38     spinsLayout->addWidget(yearSpin);
39     spinsLayout->addWidget(new QLabel(tr("year(s)")));
40     monthSpin = new QSpinBox{this};
41     monthSpin->setEnabled(false);
42     monthSpin->setMinimum(0);
43     monthSpin->setMaximum(11);
44     spinsLayout->addWidget(monthSpin);
45     spinsLayout->addWidget(new QLabel(tr("month(s)")));
46     daySpin = new QSpinBox{this};
47     daySpin->setEnabled(false);
48     daySpin->setMinimum(0);
49     daySpin->setMaximum(30);
50     spinsLayout->addWidget(daySpin);
51     spinsLayout->addWidget(new QLabel(tr("day(s)")));
52     hourSpin = new QSpinBox{this};
53     hourSpin->setEnabled(false);
54     hourSpin->setMinimum(0);
55     hourSpin->setMaximum(23);
56     spinsLayout->addWidget(hourSpin);
57     spinsLayout->addWidget(new QLabel(tr("hour(s)")));
58     minuteSpin = new QSpinBox{this};
59     minuteSpin->setEnabled(false);
60     minuteSpin->setMinimum(0);
61     minuteSpin->setMaximum(59);
62     spinsLayout->addWidget(minuteSpin);
63     spinsLayout->addWidget(new QLabel(tr("minute(s)")));
64 
65     // scope by tags
66     enableTagsScopeCheck = new QCheckBox{tr("show Notebooks with the following tags")+":", this};
67     enableTagsScopeCheck->setChecked(false);
68 
69     editTagsGroup = new EditTagsPanel{ontology, this};
70     editTagsGroup->refreshOntologyTags();
71     editTagsGroup->setTitle("");
72     // workaround to force hiding of group's title when it's empty
73     editTagsGroup->setStyleSheet("QGroupBox{padding-top:15px; margin-left:5px; margin-top:-15px}");
74     editTagsGroup->setEnabled(false);
75 
76     // dialog buttons
77     setButton = new QPushButton{tr("&Set")};
78     setButton->setDefault(true);
79 
80     closeButton = new QPushButton{tr("&Cancel")};
81 
82     QHBoxLayout *buttonLayout = new QHBoxLayout{};
83     buttonLayout->addStretch(1);
84     buttonLayout->addWidget(closeButton);
85     buttonLayout->addWidget(setButton);
86     buttonLayout->addStretch();
87 
88     // assembly
89     timepointThresholdLayout->addWidget(enableTimeScopeCheck);
90     timepointThresholdLayout->addWidget(w);
91     timepointThresholdLayout->addWidget(enableTagsScopeCheck);
92     timepointThresholdLayout->addWidget(editTagsGroup);
93     timepointThresholdLayout->addLayout(buttonLayout);
94 
95     setLayout(timepointThresholdLayout);
96 
97     // signals
98     QObject::connect(enableTimeScopeCheck, SIGNAL(clicked(bool)), this, SLOT(enableDisableTimeScope(bool)));
99     QObject::connect(enableTagsScopeCheck, SIGNAL(clicked(bool)), this, SLOT(enableDisableTagScope(bool)));
100     connect(setButton, SIGNAL(clicked()), this, SLOT(close()));
101     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
102 
103     setWindowTitle(tr("Scope Mind"));
104     resize(fontMetrics().averageCharWidth()*55, height());
105     setModal(true);
106 }
107 
~ScopeDialog()108 ScopeDialog::~ScopeDialog()
109 {
110     // TODO delete all widgets
111 }
112 
enableDisableTimeScope(bool enable)113 void ScopeDialog::enableDisableTimeScope(bool enable)
114 {
115     yearSpin->setEnabled(enable);
116     monthSpin->setEnabled(enable);
117     daySpin->setEnabled(enable);
118     hourSpin->setEnabled(enable);
119     minuteSpin->setEnabled(enable);
120 }
121 
enableDisableTagScope(bool enable)122 void ScopeDialog::enableDisableTagScope(bool enable)
123 {
124     editTagsGroup->setEnabled(enable);
125 }
126 
127 } // m8r namespace
128