transmission/qt/hig.cc

241 lines
4.4 KiB
C++
Raw Normal View History

2009-04-09 18:55:47 +00:00
/*
* This file Copyright (C) 2009-2014 Mnemosyne LLC
2009-04-09 18:55:47 +00:00
*
* It may be used under the GNU Public License v2 or v3 licenses,
* or any future license endorsed by Mnemosyne LLC.
2009-04-09 18:55:47 +00:00
*
* $Id$
2009-04-09 18:55:47 +00:00
*/
#include <iostream>
2009-04-09 18:55:47 +00:00
#include <QCheckBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include "hig.h"
2013-09-14 22:45:04 +00:00
HIG :: HIG (QWidget * parent):
QWidget (parent),
myRow (0),
myHasTall (false),
myGrid (new QGridLayout (this))
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myGrid->setContentsMargins (PAD_BIG, PAD_BIG, PAD_BIG, PAD_BIG);
myGrid->setHorizontalSpacing (PAD_BIG);
myGrid->setVerticalSpacing (PAD);
myGrid->setColumnStretch (1, 1);
2009-04-09 18:55:47 +00:00
}
2013-09-14 22:45:04 +00:00
HIG :: ~HIG ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
delete myGrid;
2009-04-09 18:55:47 +00:00
}
2009-04-09 18:55:47 +00:00
/***
****
***/
void
2013-09-14 22:45:04 +00:00
HIG :: addSectionDivider ()
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QWidget * w = new QWidget (this);
myGrid->addWidget (w, myRow, 0, 1, 2);
++myRow;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addSectionTitle (const QString& title)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QLabel * label = new QLabel (this);
label->setText (title);
label->setStyleSheet ("font: bold");
label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
addSectionTitle (label);
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addSectionTitle (QWidget * w)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myGrid->addWidget (w, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
++myRow;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addSectionTitle (QLayout * l)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myGrid->addLayout (l, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
++myRow;
2009-04-09 18:55:47 +00:00
}
QLayout *
2013-09-14 22:45:04 +00:00
HIG :: addRow (QWidget * w)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QHBoxLayout * h = new QHBoxLayout ();
h->addSpacing (18);
h->addWidget (w);
2009-04-09 18:55:47 +00:00
2013-09-14 22:45:04 +00:00
QLabel * l;
if ((l = qobject_cast<QLabel*>(w)))
l->setAlignment (Qt::AlignLeft);
2009-04-09 18:55:47 +00:00
2013-09-14 22:45:04 +00:00
return h;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addWideControl (QLayout * l)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QHBoxLayout * h = new QHBoxLayout ();
h->addSpacing (18);
h->addLayout (l);
myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
++myRow;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addWideControl (QWidget * w)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QHBoxLayout * h = new QHBoxLayout ();
h->addSpacing (18);
h->addWidget (w);
myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
++myRow;
2009-04-09 18:55:47 +00:00
}
QCheckBox*
2013-09-14 22:45:04 +00:00
HIG :: addWideCheckBox (const QString& text, bool isChecked)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QCheckBox * check = new QCheckBox (text, this);
check->setChecked (isChecked);
addWideControl (check);
return check;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addLabel (QWidget * w)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QHBoxLayout * h = new QHBoxLayout ();
h->addSpacing (18);
h->addWidget (w);
myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignVCenter);
2009-04-09 18:55:47 +00:00
}
QLabel*
2013-09-14 22:45:04 +00:00
HIG :: addLabel (const QString& text)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QLabel * label = new QLabel (text, this);
addLabel (label);
return label;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addTallLabel (QWidget * w)
{
2013-09-14 22:45:04 +00:00
QHBoxLayout * h = new QHBoxLayout ();
h->addSpacing (18);
h->addWidget (w);
myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop);
}
QLabel*
2013-09-14 22:45:04 +00:00
HIG :: addTallLabel (const QString& text)
{
2013-09-14 22:45:04 +00:00
QLabel * label = new QLabel (text, this);
addTallLabel (label);
return label;
}
2009-04-09 18:55:47 +00:00
void
2013-09-14 22:45:04 +00:00
HIG :: addControl (QWidget * w)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myGrid->addWidget (w, myRow, 1, 1, 1);
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addControl (QLayout * l)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
myGrid->addLayout (l, myRow, 1, 1, 1);
2009-04-09 18:55:47 +00:00
}
QLabel *
2013-09-14 22:45:04 +00:00
HIG :: addRow (const QString& text, QWidget * control, QWidget * buddy)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QLabel * label = addLabel (text);
addControl (control);
label->setBuddy (buddy ? buddy : control);
++myRow;
return label;
2009-04-09 18:55:47 +00:00
}
QLabel *
2013-09-14 22:45:04 +00:00
HIG :: addTallRow (const QString& text, QWidget * control, QWidget * buddy)
{
2013-09-14 22:45:04 +00:00
QLabel* label = addTallLabel (text);
label->setBuddy (buddy ? buddy : control);
addControl (control);
myHasTall = true;
myGrid->setRowStretch (myRow, 1);
++myRow;
return label;
}
2009-04-09 18:55:47 +00:00
QLabel *
2013-09-14 22:45:04 +00:00
HIG :: addRow (const QString& text, QLayout * control, QWidget * buddy)
2009-04-09 18:55:47 +00:00
{
2013-09-14 22:45:04 +00:00
QLabel * label = addLabel (text);
addControl (control);
if (buddy != 0)
label->setBuddy (buddy);
++myRow;
return label;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addRow (QWidget * label, QWidget * control, QWidget * buddy)
{
addLabel (label);
if (control)
{
addControl (control);
QLabel * l = qobject_cast<QLabel*> (label);
if (l != 0)
l->setBuddy (buddy ? buddy : control);
2009-04-09 18:55:47 +00:00
}
2013-09-14 22:45:04 +00:00
++myRow;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: addRow (QWidget * label, QLayout * control, QWidget * buddy)
{
addLabel (label);
if (control)
{
addControl (control);
QLabel * l = qobject_cast<QLabel*> (label);
if (l != 0 && buddy != 0)
l->setBuddy (buddy);
2009-04-09 18:55:47 +00:00
}
2013-09-14 22:45:04 +00:00
++myRow;
2009-04-09 18:55:47 +00:00
}
void
2013-09-14 22:45:04 +00:00
HIG :: finish ()
{
if (!myHasTall)
{
QWidget * w = new QWidget (this);
myGrid->addWidget (w, myRow, 0, 1, 2);
myGrid->setRowStretch (myRow, 100);
++myRow;
}
2009-04-09 18:55:47 +00:00
}