1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Add new widgets with simpler code than what is used currently (FancyTabWidget).

This commit is contained in:
Peter Gunnarsson 2011-08-03 10:02:51 +02:00
parent a7cce25252
commit fc2e1c7fd7
7 changed files with 385 additions and 2 deletions

View File

@ -0,0 +1,38 @@
/**
******************************************************************************
*
* @file mylistwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mylistwidget.h"
QStyleOptionViewItem MyListWidget::viewOptions() const
{
QStyleOptionViewItem option = QListWidget::viewOptions();
if (m_iconAbove) {
option.decorationPosition = QStyleOptionViewItem::Top;
option.displayAlignment = Qt::AlignCenter;
}
return option;
}

View File

@ -0,0 +1,53 @@
/**
******************************************************************************
*
* @file mylistwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MYLISTWIDGET_H
#define MYLISTWIDGET_H
#include "utils_global.h"
#include <QtGui/QListWidget>
/*
* MyListWidget is a plain QListWidget but with the added option
* to place the icon above the label in ListMode. This is achieved
* the easiest by subclassing QListWidget and overriding viewOptions().
*/
class QTCREATOR_UTILS_EXPORT MyListWidget : public QListWidget
{
Q_OBJECT
public:
MyListWidget(QWidget *parent) : QListWidget(parent), m_iconAbove(false) { }
void setIconAbove(bool iconAbove) { m_iconAbove = iconAbove; }
protected:
QStyleOptionViewItem viewOptions() const;
private:
bool m_iconAbove;
};
#endif // MYLISTWIDGET_H

View File

@ -0,0 +1,109 @@
/**
******************************************************************************
*
* @file mytabbedstackwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mytabbedstackwidget.h"
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtCore/QDebug>
MyTabbedStackWidget::MyTabbedStackWidget(QWidget *parent, bool isVertical, bool iconAbove)
: QWidget(parent),
m_vertical(isVertical),
m_iconAbove(iconAbove)
{
m_listWidget = new MyListWidget(this);
m_listWidget->setIconAbove(m_iconAbove);
m_stackWidget = new QStackedWidget();
m_stackWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QBoxLayout *toplevelLayout;
if (m_vertical) {
toplevelLayout = new QHBoxLayout;
toplevelLayout->addWidget(m_listWidget);
toplevelLayout->addWidget(m_stackWidget);
m_listWidget->setFlow(QListView::TopToBottom);
m_listWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
} else {
toplevelLayout = new QVBoxLayout;
toplevelLayout->addWidget(m_stackWidget);
toplevelLayout->addWidget(m_listWidget);
m_listWidget->setFlow(QListView::LeftToRight);
m_listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
}
if (m_iconAbove && m_vertical)
m_listWidget->setFixedWidth(90); // this should be computed instead
toplevelLayout->setSpacing(0);
toplevelLayout->setContentsMargins(0, 0, 0, 0);
m_listWidget->setSpacing(0);
m_listWidget->setContentsMargins(0, 0, 0, 0);
m_stackWidget->setContentsMargins(0, 0, 0, 0);
setLayout(toplevelLayout);
connect(m_listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showWidget(int)));
}
void MyTabbedStackWidget::insertTab(const int index, QWidget *tab, const QIcon &icon, const QString &label)
{
tab->setContentsMargins(0, 0, 0, 0);
m_stackWidget->insertWidget(index, tab);
QListWidgetItem *item = new QListWidgetItem(icon, label);
item->setToolTip(label);
m_listWidget->insertItem(index, item);
}
void MyTabbedStackWidget::removeTab(int index)
{
m_stackWidget->removeWidget(m_stackWidget->widget(index));
QListWidgetItem *item = m_listWidget->item(index);
m_listWidget->removeItemWidget(item);
delete item;
}
int MyTabbedStackWidget::currentIndex() const
{
return m_listWidget->currentRow();
}
void MyTabbedStackWidget::setCurrentIndex(int index)
{
m_listWidget->setCurrentRow(index);
}
void MyTabbedStackWidget::showWidget(int index)
{
emit currentAboutToShow(index);
m_stackWidget->setCurrentIndex(index);
emit currentChanged(index);
}
void MyTabbedStackWidget::insertCornerWidget(int index, QWidget *widget)
{
widget->hide();
}

View File

@ -0,0 +1,74 @@
/**
******************************************************************************
*
* @file mytabbedstackwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MYTABBEDSTACKWIDGET_H
#define MYTABBEDSTACKWIDGET_H
#include "utils/mylistwidget.h"
#include <QtGui/QStackedWidget>
/*
* MyTabbedStackWidget is a MyListWidget combined with a QStackedWidget,
* similar in function to QTabWidget.
*/
class QTCREATOR_UTILS_EXPORT MyTabbedStackWidget : public QWidget
{
Q_OBJECT
public:
MyTabbedStackWidget(QWidget *parent = 0, bool isVertical = false, bool iconAbove = true);
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
void removeTab(int index);
void setIconSize(int size) { m_listWidget->setIconSize(QSize(size, size)); }
int currentIndex() const;
void insertCornerWidget(int index, QWidget *widget);
int cornerWidgetCount() { return m_cornerWidgetCount; }
signals:
void currentAboutToShow(int index);
void currentChanged(int index);
public slots:
void setCurrentIndex(int index);
private slots:
void showWidget(int index);
private:
MyListWidget *m_listWidget;
QStackedWidget *m_stackWidget;
QWidget *m_selectionWidget;
bool m_vertical;
bool m_iconAbove;
int m_cornerWidgetCount;
};
#endif // MYTABBEDSTACKWIDGET_H

View File

@ -0,0 +1,48 @@
/**
******************************************************************************
*
* @file mytabwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mytabwidget.h"
#include <QtGui/QTabBar>
MyTabWidget::MyTabWidget(QWidget *parent)
: QTabWidget(parent)
{
QTabBar *tabBar = QTabWidget::tabBar();
connect(tabBar, SIGNAL(tabMoved(int, int)), this, SLOT(myTabMoved(int,int)));
}
void MyTabWidget::moveTab(int from, int to)
{
QTabBar *tabBar = QTabWidget::tabBar();
tabBar->moveTab(from, to);
}
void MyTabWidget::myTabMoved(int from, int to)
{
emit tabMoved(from, to);
}

View File

@ -0,0 +1,55 @@
/**
******************************************************************************
*
* @file mytabwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program 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; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MYTABWIDGET_H
#define MYTABWIDGET_H
#include "utils_global.h"
#include <QtGui/QTabWidget>
/*
* MyTabWidget is a plain QTabWidget with the addition of the signal
* tabMoved(int, int) which QTabBar has but for some reason is
* not made available from QTabWidget.
*/
class QTCREATOR_UTILS_EXPORT MyTabWidget : public QTabWidget
{
Q_OBJECT
public:
MyTabWidget(QWidget *parent = 0);
void moveTab(int from, int to);
private slots:
void myTabMoved(int from, int to);
signals:
void tabMoved(int from, int to);
};
#endif // MYTABWIDGET_H

View File

@ -45,7 +45,10 @@ SOURCES += reloadpromptutils.cpp \
coordinateconversions.cpp \
pathutils.cpp \
worldmagmodel.cpp \
homelocationutil.cpp
homelocationutil.cpp \
mytabbedstackwidget.cpp \
mytabwidget.cpp \
mylistwidget.cpp
SOURCES += xmlconfig.cpp
win32 {
@ -96,7 +99,10 @@ HEADERS += utils_global.h \
coordinateconversions.h \
pathutils.h \
worldmagmodel.h \
homelocationutil.h
homelocationutil.h \
mytabbedstackwidget.h \
mytabwidget.h \
mylistwidget.h
HEADERS += xmlconfig.h
FORMS += filewizardpage.ui \