Commit 536db62b authored by Julien Wintz's avatar Julien Wintz
Browse files

Fixing use of deprecated classes.

parent e08d7c9c
/* dtkToolBox.cpp ---
*
* Author: Thibaud Kloczko
* Created: lun. oct. 21 15:51:01 2013 (+0200)
*/
// Version: $Id$
//
//
/* Change Log:
*
*/
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkToolBox.h"
#include "dtkPropertyEditorFactory.h"
......@@ -29,13 +33,16 @@ dtkToolBoxButton::dtkToolBoxButton(QWidget *parent) : QAbstractButton(parent)
QSize dtkToolBoxButton::sizeHint(void) const
{
QSize iconSize(8, 8);
if (!this->icon().isNull()) {
int icone = this->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this->parentWidget() /* QToolBox */);
iconSize += QSize(icone + 2, icone);
}
QSize textSize = fontMetrics().size(Qt::TextShowMnemonic, text()) + QSize(0, 8);
QSize total(iconSize.width() + textSize.width(), qMax(iconSize.height(), textSize.height()));
return total.expandedTo(QApplication::globalStrut());
}
......@@ -43,19 +50,25 @@ QSize dtkToolBoxButton::minimumSizeHint(void) const
{
if (this->icon().isNull())
return QSize();
int icone = this->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this->parentWidget() /* QToolBox */);
return QSize(icone + 8, icone + 8);
int icon = this->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this->parentWidget());
return QSize(icon + 8, icon + 8);
}
void dtkToolBoxButton::initStyleOption(QStyleOptionToolBox *option) const
{
if (!option)
return;
option->initFrom(this);
if (this->m_selected)
option->state |= QStyle::State_Selected;
if (this->isDown())
option->state |= QStyle::State_Sunken;
option->text = this->text();
option->icon = this->icon();
}
......@@ -66,7 +79,8 @@ void dtkToolBoxButton::paintEvent(QPaintEvent *event)
QPainter paint(this);
QPainter *p = &paint;
QStyleOptionToolBoxV2 opt;
QStyleOptionToolBox opt;
this->initStyleOption(&opt);
this->style()->drawControl(QStyle::CE_ToolBoxTab, &opt, p, this->parentWidget());
}
......@@ -103,10 +117,10 @@ dtkToolBoxItem::dtkToolBoxItem(QWidget *parent) : QFrame(parent), d(new dtkToolB
d->layout = new QVBoxLayout(this);
d->layout->setContentsMargins(0, 0, 0, 0);
d->layout->setAlignment(Qt::AlignTop);
d->button = new dtkToolBoxButton(this);
d->button->show();
d->layout->addWidget(d->button);
d->widget = NULL;
......@@ -118,7 +132,7 @@ dtkToolBoxItem::dtkToolBoxItem(QWidget *parent) : QFrame(parent), d(new dtkToolB
this->connect(d->button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
dtkToolBoxItem::~dtkToolBoxItem(void)
dtkToolBoxItem::~dtkToolBoxItem(void)
{
delete d;
......@@ -169,7 +183,7 @@ void dtkToolBoxItem::setWidget(QWidget *widget, const QString& text, const QIcon
if (d->button->isVisible())
this->resize(d->button->size() + d->widget->size());
else
this->resize(d->widget->size());
this->resize(d->widget->size());
}
void dtkToolBoxItem::setExpanded(bool expanded)
......@@ -184,7 +198,7 @@ void dtkToolBoxItem::setExpanded(bool expanded)
if (expanded) {
d->widget->show();
} else {
d->widget->hide();
d->widget->hide();
}
d->button->setSelected(expanded);
}
......@@ -214,7 +228,7 @@ void dtkToolBoxItem::setName(const QString& name)
void dtkToolBoxItem::onButtonClicked(void)
{
this->setExpanded(!d->is_expanded);
if (d->box)
d->box->setCurrentItem(this);
}
......@@ -236,8 +250,9 @@ dtkToolBoxItem *dtkToolBoxItem::fromObject(QObject *object, int hierarchy_level)
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);
layout->setAlignment(Qt::AlignTop);
QString name;
foreach(QWidget *w, list) {
name = QString(w->objectName()).append(":");
layout->addWidget(new QLabel(name, frame));
......@@ -292,7 +307,7 @@ void dtkToolBoxPrivate::clear(void)
}
void dtkToolBoxPrivate::relayout(void)
{
{
if (this->layout)
delete this->layout;
......@@ -303,52 +318,62 @@ void dtkToolBoxPrivate::relayout(void)
switch(this->order) {
case dtkToolBox::Ascending:
{
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
this->layout->addWidget(*it);
++it;
}
break;
case dtkToolBox::Ascending: {
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
this->layout->addWidget(*it);
++it;
}
case dtkToolBox::Descending:
{
ItemList::ConstIterator it = items.constEnd();
while (it != items.constBegin()) {
--it;
this->layout->addWidget(*it);
}
break;
break;
}
case dtkToolBox::Descending: {
ItemList::ConstIterator it = items.constEnd();
while (it != items.constBegin()) {
--it;
this->layout->addWidget(*it);
}
case dtkToolBox::AlphaBetics:
{
QMultiMap<QString, dtkToolBoxItem *> map;
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
dtkToolBoxItem *item = *it;
map.insert(item->name(), item);
++it;
}
QMultiMap<QString, dtkToolBoxItem *>::ConstIterator i = map.constBegin();
while (i != map.constEnd()) {
this->layout->addWidget(i.value());
++i;
}
break;
break;
}
case dtkToolBox::AlphaBetics: {
QMultiMap<QString, dtkToolBoxItem *> map;
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
dtkToolBoxItem *item = *it;
map.insert(item->name(), item);
++it;
}
default:
{
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
this->layout->addWidget(*it);
++it;
}
break;
QMultiMap<QString, dtkToolBoxItem *>::ConstIterator i = map.constBegin();
while (i != map.constEnd()) {
this->layout->addWidget(i.value());
++i;
}
break;
}
default: {
ItemList::ConstIterator it = items.constBegin();
while (it != items.constEnd()) {
this->layout->addWidget(*it);
++it;
}
break;
}
}
}
......@@ -356,29 +381,31 @@ void dtkToolBoxPrivate::insert(int index, dtkToolBoxItem *item)
{
switch(this->order) {
case dtkToolBox::Ascending:
{
case dtkToolBox::Ascending: {
this->layout->insertWidget(index, item);
break;
}
case dtkToolBox::Descending:
{
this->layout->insertWidget(this->items.count() - index, item);
break;
}
}
case dtkToolBox::AlphaBetics:
{
this->relayout();
break;
}
default:
{
this->layout->insertWidget(index, item);
break;
}
case dtkToolBox::Descending: {
this->layout->insertWidget(this->items.count() - index, item);
break;
}
case dtkToolBox::AlphaBetics: {
this->relayout();
break;
}
default: {
this->layout->insertWidget(index, item);
break;
}
}
}
......@@ -388,7 +415,7 @@ void dtkToolBoxPrivate::setCurrentItem(dtkToolBoxItem *item)
this->current_item = NULL;
else
this->current_item = item;
if (this->mode == dtkToolBox::OneItemExpanded) {
foreach(dtkToolBoxItem *it, this->items) {
......@@ -512,8 +539,11 @@ void dtkToolBox::setDisplayMode(DisplayMode mode)
break;
default:
break;
}
}
foreach(dtkToolBoxItem * item, d->items)
item->setEnforced(display_all_items);
}
//
// dtkToolBox.cpp ends here
/* dtkToolBox.h ---
*
* Author: Thibaud Kloczko
* Created: lun. oct. 21 15:28:34 2013 (+0200)
*/
// Version: $Id$
//
//
/* Change Log:
*
*/
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
......@@ -15,7 +19,7 @@
#include <QtWidgets>
// ///////////////////////////////////////////////////////////////////
//
//
// ///////////////////////////////////////////////////////////////////
class DTKWIDGETS_EXPORT dtkToolBoxButton : public QAbstractButton
......@@ -52,7 +56,7 @@ inline bool dtkToolBoxButton::isSelected(void) const
}
// ///////////////////////////////////////////////////////////////////
//
//
// ///////////////////////////////////////////////////////////////////
class dtkToolBox;
......@@ -99,7 +103,7 @@ private:
};
// ///////////////////////////////////////////////////////////////////
//
//
// ///////////////////////////////////////////////////////////////////
class dtkToolBoxPrivate;
......@@ -140,14 +144,14 @@ public:
public:
dtkToolBoxItem *itemAt(int index) const;
public:
void addItem(dtkToolBoxItem *item);
void insertItem(int index, dtkToolBoxItem *item);
public:
void setCurrentItem(dtkToolBoxItem *item);
public:
void removeItem(int index);
void removeItem(dtkToolBoxItem *item);
......@@ -164,3 +168,6 @@ inline void dtkToolBox::addItem(dtkToolBoxItem *item)
{
this->insertItem(this->count(), item);
}
//
// dtkToolBox.h ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment