source: trunk/qt/hig.cc @ 14225

Last change on this file since 14225 was 14225, checked in by jordan, 9 years ago

Licensing changes:

  1. add the option the code to be used under GPLv2 or GPLv3; previously only GPLv2 was allowed
  1. add the "proxy option" as described in GPLv3 so we can add future licenses without having to bulk-edit everything again :)
  1. remove the awkward "exception for MIT code in Mac client" clause; it was unnecessary and confusing.
  • Property svn:keywords set to Date Rev Author Id
File size: 4.4 KB
Line 
1/*
2 * This file Copyright (C) 2009-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU Public License v2 or v3 licenses,
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: hig.cc 14225 2014-01-19 01:09:44Z jordan $
8 */
9
10#include <iostream>
11
12#include <QCheckBox>
13#include <QGridLayout>
14#include <QHBoxLayout>
15#include <QLabel>
16
17#include "hig.h"
18
19
20HIG :: HIG (QWidget * parent):
21  QWidget (parent),
22  myRow (0),
23  myHasTall (false),
24  myGrid (new QGridLayout (this))
25{
26  myGrid->setContentsMargins (PAD_BIG, PAD_BIG, PAD_BIG, PAD_BIG);
27  myGrid->setHorizontalSpacing (PAD_BIG);
28  myGrid->setVerticalSpacing (PAD);
29  myGrid->setColumnStretch  (1, 1);
30}
31
32HIG :: ~HIG ()
33{
34  delete myGrid;
35}
36
37/***
38****
39***/
40
41void
42HIG :: addSectionDivider ()
43{
44  QWidget * w = new QWidget (this);
45  myGrid->addWidget (w, myRow, 0, 1, 2);
46  ++myRow;
47}
48
49void
50HIG :: addSectionTitle (const QString& title)
51{
52  QLabel * label = new QLabel (this);
53  label->setText (title);
54  label->setStyleSheet ("font: bold");
55  label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
56  addSectionTitle (label);
57}
58
59void
60HIG :: addSectionTitle (QWidget * w)
61{
62  myGrid->addWidget (w, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
63  ++myRow;
64}
65
66void
67HIG :: addSectionTitle (QLayout * l)
68{
69  myGrid->addLayout (l, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
70  ++myRow;
71}
72
73
74QLayout *
75HIG :: addRow (QWidget * w)
76{
77  QHBoxLayout * h = new QHBoxLayout ();
78  h->addSpacing (18);
79  h->addWidget (w);
80
81  QLabel * l;
82  if ((l = qobject_cast<QLabel*>(w)))
83    l->setAlignment (Qt::AlignLeft);
84
85  return h;
86}
87
88void
89HIG :: addWideControl (QLayout * l)
90{
91  QHBoxLayout * h = new QHBoxLayout ();
92  h->addSpacing (18);
93  h->addLayout (l);
94  myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
95  ++myRow;
96}
97
98void
99HIG :: addWideControl (QWidget * w)
100{
101  QHBoxLayout * h = new QHBoxLayout ();
102  h->addSpacing (18);
103  h->addWidget (w);
104  myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
105  ++myRow;
106}
107
108QCheckBox*
109HIG :: addWideCheckBox (const QString& text, bool isChecked)
110{
111  QCheckBox * check = new QCheckBox (text, this);
112  check->setChecked (isChecked);
113  addWideControl (check);
114  return check;
115}
116
117void
118HIG :: addLabel (QWidget * w)
119{
120  QHBoxLayout * h = new QHBoxLayout ();
121  h->addSpacing (18);
122  h->addWidget (w);
123  myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignVCenter);
124}
125
126QLabel*
127HIG :: addLabel (const QString& text)
128{
129  QLabel * label = new QLabel (text, this);
130  addLabel (label);
131  return label;
132}
133
134void
135HIG :: addTallLabel (QWidget * w)
136{
137  QHBoxLayout * h = new QHBoxLayout ();
138  h->addSpacing (18);
139  h->addWidget (w);
140  myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop);
141}
142
143QLabel*
144HIG :: addTallLabel (const QString& text)
145{
146  QLabel * label = new QLabel (text, this);
147  addTallLabel (label);
148  return label;
149}
150
151void
152HIG :: addControl (QWidget * w)
153{
154  myGrid->addWidget (w, myRow, 1, 1, 1);
155}
156
157void
158HIG :: addControl (QLayout * l)
159{
160  myGrid->addLayout (l, myRow, 1, 1, 1);
161}
162
163QLabel *
164HIG :: addRow (const QString& text, QWidget * control, QWidget * buddy)
165{
166  QLabel * label = addLabel (text);
167  addControl (control);
168  label->setBuddy (buddy ? buddy : control);
169  ++myRow;
170  return label;
171}
172
173QLabel *
174HIG :: addTallRow (const QString& text, QWidget * control, QWidget * buddy)
175{
176  QLabel* label = addTallLabel (text);
177  label->setBuddy (buddy ? buddy : control);
178  addControl (control);
179  myHasTall = true;
180  myGrid->setRowStretch  (myRow, 1);
181  ++myRow;
182  return label;
183}
184
185QLabel *
186HIG :: addRow (const QString& text, QLayout * control, QWidget * buddy)
187{
188  QLabel * label = addLabel (text);
189  addControl (control);
190  if (buddy != 0)
191    label->setBuddy (buddy);
192  ++myRow;
193  return label;
194}
195
196void
197HIG :: addRow (QWidget * label, QWidget * control, QWidget * buddy)
198{
199  addLabel (label);
200
201  if (control)
202    {
203      addControl (control);
204
205      QLabel * l = qobject_cast<QLabel*> (label);
206      if (l != 0)
207        l->setBuddy (buddy ? buddy : control);
208    }
209
210  ++myRow;
211}
212
213void
214HIG :: addRow (QWidget * label, QLayout * control, QWidget * buddy)
215{
216  addLabel (label);
217
218  if (control)
219    {
220      addControl (control);
221
222      QLabel * l = qobject_cast<QLabel*> (label);
223      if (l != 0 && buddy != 0)
224        l->setBuddy (buddy);
225    }
226
227  ++myRow;
228}
229
230void
231HIG :: finish ()
232{
233  if (!myHasTall)
234    {
235      QWidget * w = new QWidget (this);
236      myGrid->addWidget (w, myRow, 0, 1, 2);
237      myGrid->setRowStretch (myRow, 100);
238      ++myRow;
239    }
240}
Note: See TracBrowser for help on using the repository browser.