diff --git a/ground/openpilotgcs/src/libs/utils/basevalidatinglineedit.h b/ground/openpilotgcs/src/libs/utils/basevalidatinglineedit.h index 9d4cd67b7..dde4c1983 100644 --- a/ground/openpilotgcs/src/libs/utils/basevalidatinglineedit.h +++ b/ground/openpilotgcs/src/libs/utils/basevalidatinglineedit.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { struct BaseValidatingLineEditPrivate; diff --git a/ground/openpilotgcs/src/libs/utils/cachedsvgitem.cpp b/ground/openpilotgcs/src/libs/utils/cachedsvgitem.cpp index 6cf8d7643..91627479e 100644 --- a/ground/openpilotgcs/src/libs/utils/cachedsvgitem.cpp +++ b/ground/openpilotgcs/src/libs/utils/cachedsvgitem.cpp @@ -23,7 +23,6 @@ */ #include "cachedsvgitem.h" -#include #include #ifndef GL_CLAMP_TO_EDGE diff --git a/ground/openpilotgcs/src/libs/utils/cachedsvgitem.h b/ground/openpilotgcs/src/libs/utils/cachedsvgitem.h index de88d5281..2115a37a1 100644 --- a/ground/openpilotgcs/src/libs/utils/cachedsvgitem.h +++ b/ground/openpilotgcs/src/libs/utils/cachedsvgitem.h @@ -26,7 +26,8 @@ #define CACHEDSVGITEM_H #include -#include +#include +#include #include "utils_global.h" diff --git a/ground/openpilotgcs/src/libs/utils/checkablemessagebox.cpp b/ground/openpilotgcs/src/libs/utils/checkablemessagebox.cpp index 83c344cbc..0665cf346 100644 --- a/ground/openpilotgcs/src/libs/utils/checkablemessagebox.cpp +++ b/ground/openpilotgcs/src/libs/utils/checkablemessagebox.cpp @@ -29,7 +29,7 @@ #include "checkablemessagebox.h" #include "ui_checkablemessagebox.h" -#include +#include #include namespace Utils { diff --git a/ground/openpilotgcs/src/libs/utils/checkablemessagebox.h b/ground/openpilotgcs/src/libs/utils/checkablemessagebox.h index d1565fe80..eae730742 100644 --- a/ground/openpilotgcs/src/libs/utils/checkablemessagebox.h +++ b/ground/openpilotgcs/src/libs/utils/checkablemessagebox.h @@ -31,9 +31,9 @@ #include "utils_global.h" -#include -#include -#include +#include +#include +#include namespace Utils { struct CheckableMessageBoxPrivate; diff --git a/ground/openpilotgcs/src/libs/utils/detailsbutton.h b/ground/openpilotgcs/src/libs/utils/detailsbutton.h index efe36a8d3..fdb36239e 100644 --- a/ground/openpilotgcs/src/libs/utils/detailsbutton.h +++ b/ground/openpilotgcs/src/libs/utils/detailsbutton.h @@ -29,8 +29,8 @@ #ifndef DETAILSBUTTON_H #define DETAILSBUTTON_H -#include -#include +#include +#include #include "utils_global.h" diff --git a/ground/openpilotgcs/src/libs/utils/detailswidget.cpp b/ground/openpilotgcs/src/libs/utils/detailswidget.cpp index 2de40e972..11a95537b 100644 --- a/ground/openpilotgcs/src/libs/utils/detailswidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/detailswidget.cpp @@ -29,11 +29,11 @@ #include "detailswidget.h" #include "detailsbutton.h" -#include +#include #include -#include -#include -#include +#include +#include +#include using namespace Utils; diff --git a/ground/openpilotgcs/src/libs/utils/detailswidget.h b/ground/openpilotgcs/src/libs/utils/detailswidget.h index 71ea2f23e..0813a6d9f 100644 --- a/ground/openpilotgcs/src/libs/utils/detailswidget.h +++ b/ground/openpilotgcs/src/libs/utils/detailswidget.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include QT_BEGIN_NAMESPACE class QLabel; diff --git a/ground/openpilotgcs/src/libs/utils/fancylineedit.cpp b/ground/openpilotgcs/src/libs/utils/fancylineedit.cpp index a0c7f40c6..9e552e262 100644 --- a/ground/openpilotgcs/src/libs/utils/fancylineedit.cpp +++ b/ground/openpilotgcs/src/libs/utils/fancylineedit.cpp @@ -31,10 +31,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include enum { margin = 6 }; diff --git a/ground/openpilotgcs/src/libs/utils/fancylineedit.h b/ground/openpilotgcs/src/libs/utils/fancylineedit.h index 09eceabe7..5ff5f3389 100644 --- a/ground/openpilotgcs/src/libs/utils/fancylineedit.h +++ b/ground/openpilotgcs/src/libs/utils/fancylineedit.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { class FancyLineEditPrivate; diff --git a/ground/openpilotgcs/src/libs/utils/fancymainwindow.cpp b/ground/openpilotgcs/src/libs/utils/fancymainwindow.cpp index ea03c92c8..33a728eb4 100644 --- a/ground/openpilotgcs/src/libs/utils/fancymainwindow.cpp +++ b/ground/openpilotgcs/src/libs/utils/fancymainwindow.cpp @@ -28,34 +28,89 @@ #include "fancymainwindow.h" -#include -#include -#include -#include +#include "qtcassert.h" +#include +#include +#include +#include -using namespace Utils; +static const char lockedKeyC[] = "Locked"; +static const char stateKeyC[] = "State"; +static const int settingsVersion = 2; +static const char dockWidgetActiveState[] = "DockWidgetActiveState"; -FancyMainWindow::FancyMainWindow(QWidget *parent) - : QMainWindow(parent), +namespace Utils { + +/*! \class Utils::FancyMainWindow + + \brief MainWindow with dock widgets and additional "lock" functionality + (locking the dock widgets in place) and "reset layout" functionality. + + The dock actions and the additional actions should be accessible + in a Window-menu. +*/ + +struct FancyMainWindowPrivate +{ + FancyMainWindowPrivate(); + + bool m_locked; + bool m_handleDockVisibilityChanges; + + QAction m_menuSeparator1; + QAction m_toggleLockedAction; + QAction m_menuSeparator2; + QAction m_resetLayoutAction; + QDockWidget *m_toolBarDockWidget; +}; + +FancyMainWindowPrivate::FancyMainWindowPrivate() : m_locked(true), - m_handleDockVisibilityChanges(true) -{} + m_handleDockVisibilityChanges(true), + m_menuSeparator1(0), + m_toggleLockedAction(FancyMainWindow::tr("Locked"), 0), + m_menuSeparator2(0), + m_resetLayoutAction(FancyMainWindow::tr("Reset to Default Layout"), 0), + m_toolBarDockWidget(0) +{ + m_toggleLockedAction.setCheckable(true); + m_toggleLockedAction.setChecked(m_locked); + m_menuSeparator1.setSeparator(true); + m_menuSeparator2.setSeparator(true); +} + +FancyMainWindow::FancyMainWindow(QWidget *parent) : + QMainWindow(parent), d(new FancyMainWindowPrivate) +{ + connect(&d->m_toggleLockedAction, SIGNAL(toggled(bool)), + this, SLOT(setLocked(bool))); + connect(&d->m_resetLayoutAction, SIGNAL(triggered()), + this, SIGNAL(resetLayout())); +} + +FancyMainWindow::~FancyMainWindow() +{ + delete d; +} QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget) { QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this); - - dockWidget->setObjectName(widget->windowTitle()); dockWidget->setWidget(widget); + // Set an object name to be used in settings, derive from widget name + const QString objectName = widget->objectName(); + if (objectName.isEmpty()) + dockWidget->setObjectName(QLatin1String("dockWidget") + QString::number(dockWidgets().size() + 1)); + else + dockWidget->setObjectName(objectName + QLatin1String("DockWidget")); connect(dockWidget->toggleViewAction(), SIGNAL(triggered()), - this, SLOT(onDockActionTriggered()), Qt::QueuedConnection); + this, SLOT(onDockActionTriggered()), Qt::QueuedConnection); connect(dockWidget, SIGNAL(visibilityChanged(bool)), this, SLOT(onDockVisibilityChange(bool))); connect(dockWidget, SIGNAL(topLevelChanged(bool)), this, SLOT(onTopLevelChanged())); - m_dockWidgets.append(dockWidget); - m_dockWidgetActiveState.append(true); + dockWidget->setProperty(dockWidgetActiveState, true); updateDockWidget(dockWidget); return dockWidget; } @@ -63,62 +118,56 @@ QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget) void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget) { const QDockWidget::DockWidgetFeatures features = - (m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable - : QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable; - QWidget *titleBarWidget = dockWidget->titleBarWidget(); - - if (m_locked && !titleBarWidget && !dockWidget->isFloating()) { - titleBarWidget = new QWidget(dockWidget); - } else if ((!m_locked || dockWidget->isFloating()) && titleBarWidget) { - delete titleBarWidget; - titleBarWidget = 0; + (d->m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable + : QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable; + if (dockWidget->property("managed_dockwidget").isNull()) { // for the debugger tool bar + QWidget *titleBarWidget = dockWidget->titleBarWidget(); + if (d->m_locked && !titleBarWidget && !dockWidget->isFloating()) + titleBarWidget = new QWidget(dockWidget); + else if ((!d->m_locked || dockWidget->isFloating()) && titleBarWidget) { + delete titleBarWidget; + titleBarWidget = 0; + } + dockWidget->setTitleBarWidget(titleBarWidget); } - dockWidget->setTitleBarWidget(titleBarWidget); dockWidget->setFeatures(features); } void FancyMainWindow::onDockActionTriggered() { QDockWidget *dw = qobject_cast(sender()->parent()); - if (dw) { - if (dw->isVisible()) { + if (dw->isVisible()) dw->raise(); - } } } void FancyMainWindow::onDockVisibilityChange(bool visible) { - if (!m_handleDockVisibilityChanges) { - return; - } - QDockWidget *dockWidget = qobject_cast(sender()); - int index = m_dockWidgets.indexOf(dockWidget); - m_dockWidgetActiveState[index] = visible; + if (d->m_handleDockVisibilityChanges) + sender()->setProperty(dockWidgetActiveState, visible); } void FancyMainWindow::onTopLevelChanged() { - updateDockWidget(qobject_cast(sender())); + updateDockWidget(qobject_cast(sender())); } void FancyMainWindow::setTrackingEnabled(bool enabled) { if (enabled) { - m_handleDockVisibilityChanges = true; - for (int i = 0; i < m_dockWidgets.size(); ++i) { - m_dockWidgetActiveState[i] = m_dockWidgets[i]->isVisible(); - } + d->m_handleDockVisibilityChanges = true; + foreach (QDockWidget *dockWidget, dockWidgets()) + dockWidget->setProperty(dockWidgetActiveState, dockWidget->isVisible()); } else { - m_handleDockVisibilityChanges = false; + d->m_handleDockVisibilityChanges = false; } } void FancyMainWindow::setLocked(bool locked) { - m_locked = locked; - foreach(QDockWidget * dockWidget, m_dockWidgets) { + d->m_locked = locked; + foreach (QDockWidget *dockWidget, dockWidgets()) { updateDockWidget(dockWidget); } } @@ -135,18 +184,24 @@ void FancyMainWindow::showEvent(QShowEvent *event) handleVisibilityChanged(true); } +void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu *menu = createPopupMenu(); + menu->exec(event->globalPos()); + delete menu; +} + void FancyMainWindow::handleVisibilityChanged(bool visible) { - m_handleDockVisibilityChanges = false; - for (int i = 0; i < m_dockWidgets.size(); ++i) { - QDockWidget *dockWidget = m_dockWidgets.at(i); + d->m_handleDockVisibilityChanges = false; + foreach (QDockWidget *dockWidget, dockWidgets()) { if (dockWidget->isFloating()) { - dockWidget->setVisible(visible && m_dockWidgetActiveState.at(i)); + dockWidget->setVisible(visible + && dockWidget->property(dockWidgetActiveState).toBool()); } } - if (visible) { - m_handleDockVisibilityChanges = true; - } + if (visible) + d->m_handleDockVisibilityChanges = true; } void FancyMainWindow::saveSettings(QSettings *settings) const @@ -159,10 +214,10 @@ void FancyMainWindow::saveSettings(QSettings *settings) const } } -void FancyMainWindow::restoreSettings(QSettings *settings) +void FancyMainWindow::restoreSettings(const QSettings *settings) { QHash hash; - foreach(const QString &key, settings->childKeys()) { + foreach (const QString &key, settings->childKeys()) { hash.insert(key, settings->value(key)); } restoreSettings(hash); @@ -171,24 +226,105 @@ void FancyMainWindow::restoreSettings(QSettings *settings) QHash FancyMainWindow::saveSettings() const { QHash settings; - settings["State"] = saveState(); - settings["Locked"] = m_locked; - for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) { - settings[m_dockWidgets.at(i)->objectName()] = - m_dockWidgetActiveState.at(i); + settings.insert(QLatin1String(stateKeyC), saveState(settingsVersion)); + settings.insert(QLatin1String(lockedKeyC), d->m_locked); + foreach (QDockWidget *dockWidget, dockWidgets()) { + settings.insert(dockWidget->objectName(), + dockWidget->property(dockWidgetActiveState)); } return settings; } void FancyMainWindow::restoreSettings(const QHash &settings) { - QByteArray ba = settings.value("State", QByteArray()).toByteArray(); - - if (!ba.isEmpty()) { - restoreState(ba); - } - m_locked = settings.value("Locked", true).toBool(); - for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) { - m_dockWidgetActiveState[i] = settings.value(m_dockWidgets.at(i)->objectName(), false).toBool(); + QByteArray ba = settings.value(QLatin1String(stateKeyC), QByteArray()).toByteArray(); + if (!ba.isEmpty()) + restoreState(ba, settingsVersion); + d->m_locked = settings.value(QLatin1String("Locked"), true).toBool(); + d->m_toggleLockedAction.setChecked(d->m_locked); + foreach (QDockWidget *widget, dockWidgets()) { + widget->setProperty(dockWidgetActiveState, + settings.value(widget->objectName(), false)); } } + +QList FancyMainWindow::dockWidgets() const +{ + return findChildren(); +} + +bool FancyMainWindow::isLocked() const +{ + return d->m_locked; +} + +static bool actionLessThan(const QAction *action1, const QAction *action2) +{ + QTC_ASSERT(action1, return true); + QTC_ASSERT(action2, return false); + return action1->text().toLower() < action2->text().toLower(); +} + +QMenu *FancyMainWindow::createPopupMenu() +{ + QList actions; + QList dockwidgets = findChildren(); + for (int i = 0; i < dockwidgets.size(); ++i) { + QDockWidget *dockWidget = dockwidgets.at(i); + if (dockWidget->property("managed_dockwidget").isNull() + && dockWidget->parentWidget() == this) { + actions.append(dockwidgets.at(i)->toggleViewAction()); + } + } + qSort(actions.begin(), actions.end(), actionLessThan); + QMenu *menu = new QMenu(this); + foreach (QAction *action, actions) + menu->addAction(action); + menu->addAction(&d->m_menuSeparator1); + menu->addAction(&d->m_toggleLockedAction); + menu->addAction(&d->m_menuSeparator2); + menu->addAction(&d->m_resetLayoutAction); + return menu; +} + +QAction *FancyMainWindow::menuSeparator1() const +{ + return &d->m_menuSeparator1; +} + +QAction *FancyMainWindow::toggleLockedAction() const +{ + return &d->m_toggleLockedAction; +} + +QAction *FancyMainWindow::menuSeparator2() const +{ + return &d->m_menuSeparator2; +} + +QAction *FancyMainWindow::resetLayoutAction() const +{ + return &d->m_resetLayoutAction; +} + +void FancyMainWindow::setDockActionsVisible(bool v) +{ + foreach (const QDockWidget *dockWidget, dockWidgets()) + dockWidget->toggleViewAction()->setVisible(v); + d->m_toggleLockedAction.setVisible(v); + d->m_menuSeparator1.setVisible(v); + d->m_menuSeparator2.setVisible(v); + d->m_resetLayoutAction.setVisible(v); +} + +QDockWidget *FancyMainWindow::toolBarDockWidget() const +{ + return d->m_toolBarDockWidget; +} + +void FancyMainWindow::setToolBarDockWidget(QDockWidget *dock) +{ + d->m_toolBarDockWidget = dock; +} + +} // namespace Utils diff --git a/ground/openpilotgcs/src/libs/utils/fancymainwindow.h b/ground/openpilotgcs/src/libs/utils/fancymainwindow.h index 0d2abafeb..c5abd4c2a 100644 --- a/ground/openpilotgcs/src/libs/utils/fancymainwindow.h +++ b/ground/openpilotgcs/src/libs/utils/fancymainwindow.h @@ -31,46 +31,63 @@ #include "utils_global.h" -#include -#include - -#include +#include QT_BEGIN_NAMESPACE class QSettings; QT_END_NAMESPACE namespace Utils { -class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow { + +struct FancyMainWindowPrivate; + +class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow +{ Q_OBJECT public: - FancyMainWindow(QWidget *parent = 0); + explicit FancyMainWindow(QWidget *parent = 0); + virtual ~FancyMainWindow(); + /* The widget passed in should have an objectname set + * which will then be used as key for QSettings. */ QDockWidget *addDockForWidget(QWidget *widget); - QList dockWidgets() const - { - return m_dockWidgets; - } + QList dockWidgets() const; void setTrackingEnabled(bool enabled); - bool isLocked() const - { - return m_locked; - } + bool isLocked() const; void saveSettings(QSettings *settings) const; - void restoreSettings(QSettings *settings); + void restoreSettings(const QSettings *settings); QHash saveSettings() const; void restoreSettings(const QHash &settings); + // Additional context menu actions + QAction *menuSeparator1() const; + QAction *toggleLockedAction() const; + QAction *menuSeparator2() const; + QAction *resetLayoutAction() const; + + // Overwritten to add locked/reset. + virtual QMenu *createPopupMenu(); + + + QDockWidget *toolBarDockWidget() const; + void setToolBarDockWidget(QDockWidget *dock); + +signals: + // Emitted by resetLayoutAction(). Connect to a slot + // restoring the default layout. + void resetLayout(); + public slots: void setLocked(bool locked); + void setDockActionsVisible(bool v); protected: void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); - + void contextMenuEvent(QContextMenuEvent *event); private slots: void onDockActionTriggered(); void onDockVisibilityChange(bool); @@ -80,11 +97,9 @@ private: void updateDockWidget(QDockWidget *dockWidget); void handleVisibilityChanged(bool visible); - QList m_dockWidgets; - QList m_dockWidgetActiveState; - bool m_locked; - bool m_handleDockVisibilityChanges; // todo + FancyMainWindowPrivate *d; }; + } // namespace Utils #endif // FANCYMAINWINDOW_H diff --git a/ground/openpilotgcs/src/libs/utils/filesearch.cpp b/ground/openpilotgcs/src/libs/utils/filesearch.cpp index c728aeb78..8a40e96c7 100644 --- a/ground/openpilotgcs/src/libs/utils/filesearch.cpp +++ b/ground/openpilotgcs/src/libs/utils/filesearch.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ static inline QString msgCanceled(const QString &searchTerm, int numMatches, int { return QCoreApplication::translate("Utils::FileSearch", "%1: canceled. %n occurrences found in %2 files.", - 0, QCoreApplication::CodecForTr, numMatches). + 0, numMatches). arg(searchTerm).arg(numFilesSearched); } @@ -53,7 +53,7 @@ static inline QString msgFound(const QString &searchTerm, int numMatches, int nu { return QCoreApplication::translate("Utils::FileSearch", "%1: %n occurrences found in %2 files.", - 0, QCoreApplication::CodecForTr, numMatches). + 0, numMatches). arg(searchTerm).arg(numFilesSearched); } @@ -61,7 +61,7 @@ static inline QString msgFound(const QString &searchTerm, int numMatches, int nu { return QCoreApplication::translate("Utils::FileSearch", "%1: %n occurrences found in %2 of %3 files.", - 0, QCoreApplication::CodecForTr, numMatches). + 0, numMatches). arg(searchTerm).arg(numFilesSearched).arg(filesSize); } diff --git a/ground/openpilotgcs/src/libs/utils/filesearch.h b/ground/openpilotgcs/src/libs/utils/filesearch.h index 09802336e..223af426a 100644 --- a/ground/openpilotgcs/src/libs/utils/filesearch.h +++ b/ground/openpilotgcs/src/libs/utils/filesearch.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include namespace Utils { class QTCREATOR_UTILS_EXPORT FileSearchResult { diff --git a/ground/openpilotgcs/src/libs/utils/filewizarddialog.cpp b/ground/openpilotgcs/src/libs/utils/filewizarddialog.cpp index 552e212fd..88fdb0616 100644 --- a/ground/openpilotgcs/src/libs/utils/filewizarddialog.cpp +++ b/ground/openpilotgcs/src/libs/utils/filewizarddialog.cpp @@ -29,7 +29,7 @@ #include "filewizarddialog.h" #include "filewizardpage.h" -#include +#include namespace Utils { FileWizardDialog::FileWizardDialog(QWidget *parent) : diff --git a/ground/openpilotgcs/src/libs/utils/filewizarddialog.h b/ground/openpilotgcs/src/libs/utils/filewizarddialog.h index 5e10a2aa2..88d1262bc 100644 --- a/ground/openpilotgcs/src/libs/utils/filewizarddialog.h +++ b/ground/openpilotgcs/src/libs/utils/filewizarddialog.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { class FileWizardPage; diff --git a/ground/openpilotgcs/src/libs/utils/filewizardpage.h b/ground/openpilotgcs/src/libs/utils/filewizardpage.h index 7fa559711..569d31f0f 100644 --- a/ground/openpilotgcs/src/libs/utils/filewizardpage.h +++ b/ground/openpilotgcs/src/libs/utils/filewizardpage.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { struct FileWizardPagePrivate; diff --git a/ground/openpilotgcs/src/libs/utils/mylistwidget.cpp b/ground/openpilotgcs/src/libs/utils/hostosinfo.cpp similarity index 53% rename from ground/openpilotgcs/src/libs/utils/mylistwidget.cpp rename to ground/openpilotgcs/src/libs/utils/hostosinfo.cpp index f8a6de992..d04f5be83 100644 --- a/ground/openpilotgcs/src/libs/utils/mylistwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/hostosinfo.cpp @@ -1,14 +1,14 @@ /** ****************************************************************************** * - * @file mylistwidget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @file hostosinfo.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. - * @brief - * @see The GNU Public License (GPL) Version 3 - * @defgroup + * @addtogroup GCSPlugins GCS Plugins * @{ - * + * @addtogroup CorePlugin Core Plugin + * @{ + * @brief The Core GCS plugin *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -25,15 +25,34 @@ * 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 +#include "hostosinfo.h" + +#ifdef Q_OS_WIN +#include +#endif + +using namespace Utils; + +HostOsInfo::HostArchitecture HostOsInfo::hostArchitecture() { - QStyleOptionViewItem option = QListWidget::viewOptions(); - - if (m_iconAbove) { - option.decorationPosition = QStyleOptionViewItem::Top; - option.displayAlignment = Qt::AlignCenter; +#ifdef Q_OS_WIN + SYSTEM_INFO info; + GetNativeSystemInfo(&info); + switch (info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + return HostOsInfo::HostArchitectureAMD64; + case PROCESSOR_ARCHITECTURE_INTEL: + return HostOsInfo::HostArchitectureX86; + case PROCESSOR_ARCHITECTURE_IA64: + return HostOsInfo::HostArchitectureItanium; + case PROCESSOR_ARCHITECTURE_ARM: + return HostOsInfo::HostArchitectureArm; + default: + return HostOsInfo::HostArchitectureUnknown; } - return option; +#else + return HostOsInfo::HostArchitectureUnknown; +#endif } + diff --git a/ground/openpilotgcs/src/libs/utils/hostosinfo.h b/ground/openpilotgcs/src/libs/utils/hostosinfo.h new file mode 100644 index 000000000..deb3feb5d --- /dev/null +++ b/ground/openpilotgcs/src/libs/utils/hostosinfo.h @@ -0,0 +1,110 @@ +/** + ****************************************************************************** + * + * @file hostosinfo.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup CorePlugin Core Plugin + * @{ + * @brief The Core GCS plugin + *****************************************************************************/ +/* + * 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 HOSTOSINFO_H +#define HOSTOSINFO_H + +#include "utils_global.h" + +#include + +#ifdef Q_OS_WIN +#define QTC_HOST_EXE_SUFFIX ".exe" +#else +#define QTC_HOST_EXE_SUFFIX "" +#endif // Q_OS_WIN + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT HostOsInfo +{ +public: + // Add more as needed. + enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther }; + static inline HostOs hostOs(); + + enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium, + HostArchitectureArm, HostArchitectureUnknown }; + static HostArchitecture hostArchitecture(); + + static bool isWindowsHost() { return hostOs() == HostOsWindows; } + static bool isLinuxHost() { return hostOs() == HostOsLinux; } + static bool isMacHost() { return hostOs() == HostOsMac; } + static inline bool isAnyUnixHost(); + + static QString withExecutableSuffix(const QString &executable) + { + QString finalName = executable; + if (isWindowsHost()) + finalName += QLatin1String(QTC_HOST_EXE_SUFFIX); + return finalName; + } + + static Qt::CaseSensitivity fileNameCaseSensitivity() + { + return isWindowsHost() ? Qt::CaseInsensitive: Qt::CaseSensitive; + } + + static QChar pathListSeparator() + { + return isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':'); + } + + static Qt::KeyboardModifier controlModifier() + { + return isMacHost() ? Qt::MetaModifier : Qt::ControlModifier; + } +}; + +HostOsInfo::HostOs HostOsInfo::hostOs() +{ +#if defined(Q_OS_WIN) + return HostOsWindows; +#elif defined(Q_OS_LINUX) + return HostOsLinux; +#elif defined(Q_OS_MAC) + return HostOsMac; +#elif defined(Q_OS_UNIX) + return HostOsOtherUnix; +#else + return HostOsOther; +#endif +} + +bool HostOsInfo::isAnyUnixHost() +{ +#ifdef Q_OS_UNIX + return true; +#else + return false; +#endif +} + +} // namespace Utils + +#endif // HOSTOSINFO_H diff --git a/ground/openpilotgcs/src/libs/utils/linecolumnlabel.h b/ground/openpilotgcs/src/libs/utils/linecolumnlabel.h index 10ff22117..cd41cdeb8 100644 --- a/ground/openpilotgcs/src/libs/utils/linecolumnlabel.h +++ b/ground/openpilotgcs/src/libs/utils/linecolumnlabel.h @@ -30,7 +30,7 @@ #define LINECOLUMNLABEL_H #include "utils_global.h" -#include +#include namespace Utils { /* A label suitable for displaying cursor positions, etc. with a fixed diff --git a/ground/openpilotgcs/src/libs/utils/mylistwidget.h b/ground/openpilotgcs/src/libs/utils/mylistwidget.h deleted file mode 100644 index 7463db68f..000000000 --- a/ground/openpilotgcs/src/libs/utils/mylistwidget.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - ****************************************************************************** - * - * @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 - -/* - * 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 diff --git a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp index 20f45b08e..d8e5111d2 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp @@ -26,9 +26,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mytabbedstackwidget.h" -#include -#include -#include +#include +#include +#include #include MyTabbedStackWidget::MyTabbedStackWidget(QWidget *parent, bool isVertical, bool iconAbove) @@ -36,10 +36,9 @@ MyTabbedStackWidget::MyTabbedStackWidget(QWidget *parent, bool isVertical, bool m_vertical(isVertical), m_iconAbove(iconAbove) { - m_listWidget = new MyListWidget(this); - m_listWidget->setIconAbove(m_iconAbove); + m_listWidget = new QListWidget(this); m_stackWidget = new QStackedWidget(); - m_stackWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_stackWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); QBoxLayout *toplevelLayout; if (m_vertical) { @@ -59,13 +58,14 @@ MyTabbedStackWidget::MyTabbedStackWidget(QWidget *parent, bool isVertical, bool } if (m_iconAbove && m_vertical) { - m_listWidget->setFixedWidth(90); // this should be computed instead + m_listWidget->setFixedWidth(80); // this should be computed instead } toplevelLayout->setSpacing(0); toplevelLayout->setContentsMargins(0, 0, 0, 0); m_listWidget->setContentsMargins(0, 0, 0, 0); m_listWidget->setSpacing(0); + m_listWidget->setViewMode(QListView::IconMode); m_stackWidget->setContentsMargins(0, 0, 0, 0); setLayout(toplevelLayout); @@ -77,6 +77,7 @@ void MyTabbedStackWidget::insertTab(const int index, QWidget *tab, const QIcon & tab->setContentsMargins(0, 0, 0, 0); m_stackWidget->insertWidget(index, tab); QListWidgetItem *item = new QListWidgetItem(icon, label); + item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom); item->setToolTip(label); m_listWidget->insertItem(index, item); } diff --git a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h index 6862ee426..d5e191028 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h +++ b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h @@ -29,13 +29,10 @@ #ifndef MYTABBEDSTACKWIDGET_H #define MYTABBEDSTACKWIDGET_H -#include "utils/mylistwidget.h" -#include +#include +#include +#include "utils_global.h" -/* - * MyTabbedStackWidget is a MyListWidget combined with a QStackedWidget, - * similar in function to QTabWidget. - */ class QTCREATOR_UTILS_EXPORT MyTabbedStackWidget : public QWidget { Q_OBJECT @@ -78,7 +75,7 @@ private slots: void showWidget(int index); private: - MyListWidget *m_listWidget; + QListWidget *m_listWidget; QStackedWidget *m_stackWidget; QWidget *m_selectionWidget; bool m_vertical; diff --git a/ground/openpilotgcs/src/libs/utils/mytabwidget.cpp b/ground/openpilotgcs/src/libs/utils/mytabwidget.cpp index 330312777..8c0098775 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/mytabwidget.cpp @@ -26,7 +26,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mytabwidget.h" -#include +#include MyTabWidget::MyTabWidget(QWidget *parent) : QTabWidget(parent) diff --git a/ground/openpilotgcs/src/libs/utils/mytabwidget.h b/ground/openpilotgcs/src/libs/utils/mytabwidget.h index 6110c13c6..34e3b2ec9 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabwidget.h +++ b/ground/openpilotgcs/src/libs/utils/mytabwidget.h @@ -30,7 +30,7 @@ #include "utils_global.h" -#include +#include /* * MyTabWidget is a plain QTabWidget with the addition of the signal diff --git a/ground/openpilotgcs/src/libs/utils/newclasswidget.cpp b/ground/openpilotgcs/src/libs/utils/newclasswidget.cpp index 844dbd68c..74152983b 100644 --- a/ground/openpilotgcs/src/libs/utils/newclasswidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/newclasswidget.cpp @@ -31,7 +31,7 @@ #include -#include +#include #include #include #include diff --git a/ground/openpilotgcs/src/libs/utils/newclasswidget.h b/ground/openpilotgcs/src/libs/utils/newclasswidget.h index eff073719..ccb89162d 100644 --- a/ground/openpilotgcs/src/libs/utils/newclasswidget.h +++ b/ground/openpilotgcs/src/libs/utils/newclasswidget.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include QT_BEGIN_NAMESPACE class QStringList; diff --git a/ground/openpilotgcs/src/libs/utils/parameteraction.h b/ground/openpilotgcs/src/libs/utils/parameteraction.h index 5c36f84d9..52cee193f 100644 --- a/ground/openpilotgcs/src/libs/utils/parameteraction.h +++ b/ground/openpilotgcs/src/libs/utils/parameteraction.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { /* ParameterAction: Intended for actions that act on a 'current', diff --git a/ground/openpilotgcs/src/libs/utils/pathchooser.cpp b/ground/openpilotgcs/src/libs/utils/pathchooser.cpp index e166c66da..18e420c01 100644 --- a/ground/openpilotgcs/src/libs/utils/pathchooser.cpp +++ b/ground/openpilotgcs/src/libs/utils/pathchooser.cpp @@ -36,12 +36,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /*static*/ const char *const Utils::PathChooser::browseButtonLabel = #ifdef Q_WS_MAC @@ -280,7 +280,7 @@ QString PathChooser::homePath() // Return 'users//Documents' on Windows, since Windows explorer // does not let people actually display the contents of their home // directory. Alternatively, create a QtCreator-specific directory? - return QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + return QStandardPaths::displayName(QStandardPaths::DocumentsLocation); #else return QDir::homePath(); diff --git a/ground/openpilotgcs/src/libs/utils/pathchooser.h b/ground/openpilotgcs/src/libs/utils/pathchooser.h index 3da12a7a0..8540d7fe9 100644 --- a/ground/openpilotgcs/src/libs/utils/pathchooser.h +++ b/ground/openpilotgcs/src/libs/utils/pathchooser.h @@ -31,8 +31,8 @@ #include "utils_global.h" -#include -#include +#include +#include namespace Utils { struct PathChooserPrivate; diff --git a/ground/openpilotgcs/src/libs/utils/pathlisteditor.cpp b/ground/openpilotgcs/src/libs/utils/pathlisteditor.cpp index 944dd6195..92c3eed99 100644 --- a/ground/openpilotgcs/src/libs/utils/pathlisteditor.cpp +++ b/ground/openpilotgcs/src/libs/utils/pathlisteditor.cpp @@ -28,16 +28,16 @@ #include "pathlisteditor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/ground/openpilotgcs/src/libs/utils/pathlisteditor.h b/ground/openpilotgcs/src/libs/utils/pathlisteditor.h index 8bdec3c01..cc82b9d3d 100644 --- a/ground/openpilotgcs/src/libs/utils/pathlisteditor.h +++ b/ground/openpilotgcs/src/libs/utils/pathlisteditor.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/ground/openpilotgcs/src/libs/utils/pathutils.h b/ground/openpilotgcs/src/libs/utils/pathutils.h index 0a0b82f09..659ea6e91 100644 --- a/ground/openpilotgcs/src/libs/utils/pathutils.h +++ b/ground/openpilotgcs/src/libs/utils/pathutils.h @@ -32,7 +32,7 @@ #include "utils_global.h" #include "../extensionsystem/pluginmanager.h" #include -#include +#include #include namespace Utils { diff --git a/ground/openpilotgcs/src/libs/utils/projectintropage.cpp b/ground/openpilotgcs/src/libs/utils/projectintropage.cpp index 2eafc29d9..4cf4c43da 100644 --- a/ground/openpilotgcs/src/libs/utils/projectintropage.cpp +++ b/ground/openpilotgcs/src/libs/utils/projectintropage.cpp @@ -30,7 +30,7 @@ #include "filewizardpage.h" #include "ui_projectintropage.h" -#include +#include #include #include diff --git a/ground/openpilotgcs/src/libs/utils/projectintropage.h b/ground/openpilotgcs/src/libs/utils/projectintropage.h index 03a2495e1..c1c6eddc2 100644 --- a/ground/openpilotgcs/src/libs/utils/projectintropage.h +++ b/ground/openpilotgcs/src/libs/utils/projectintropage.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { struct ProjectIntroPagePrivate; diff --git a/ground/openpilotgcs/src/libs/utils/qtcolorbutton.cpp b/ground/openpilotgcs/src/libs/utils/qtcolorbutton.cpp index d05368ca6..222e204c1 100644 --- a/ground/openpilotgcs/src/libs/utils/qtcolorbutton.cpp +++ b/ground/openpilotgcs/src/libs/utils/qtcolorbutton.cpp @@ -29,10 +29,11 @@ #include "qtcolorbutton.h" #include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Utils { class QtColorButtonPrivate { diff --git a/ground/openpilotgcs/src/libs/utils/qtcolorbutton.h b/ground/openpilotgcs/src/libs/utils/qtcolorbutton.h index 8773bcd59..fd8991819 100644 --- a/ground/openpilotgcs/src/libs/utils/qtcolorbutton.h +++ b/ground/openpilotgcs/src/libs/utils/qtcolorbutton.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include namespace Utils { class QTCREATOR_UTILS_EXPORT QtColorButton : public QToolButton { diff --git a/ground/openpilotgcs/src/libs/utils/reloadpromptutils.cpp b/ground/openpilotgcs/src/libs/utils/reloadpromptutils.cpp index c7532f7c6..38f043e42 100644 --- a/ground/openpilotgcs/src/libs/utils/reloadpromptutils.cpp +++ b/ground/openpilotgcs/src/libs/utils/reloadpromptutils.cpp @@ -28,7 +28,7 @@ #include "reloadpromptutils.h" -#include +#include #include #include diff --git a/ground/openpilotgcs/src/libs/utils/savedaction.cpp b/ground/openpilotgcs/src/libs/utils/savedaction.cpp index b0e551896..3dc5af538 100644 --- a/ground/openpilotgcs/src/libs/utils/savedaction.cpp +++ b/ground/openpilotgcs/src/libs/utils/savedaction.cpp @@ -34,13 +34,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include using namespace Utils; diff --git a/ground/openpilotgcs/src/libs/utils/savedaction.h b/ground/openpilotgcs/src/libs/utils/savedaction.h index df624c637..9f8721bde 100644 --- a/ground/openpilotgcs/src/libs/utils/savedaction.h +++ b/ground/openpilotgcs/src/libs/utils/savedaction.h @@ -35,7 +35,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE class QSettings; diff --git a/ground/openpilotgcs/src/libs/utils/styledbar.cpp b/ground/openpilotgcs/src/libs/utils/styledbar.cpp index 7ceb6709b..f5bf5ffb3 100644 --- a/ground/openpilotgcs/src/libs/utils/styledbar.cpp +++ b/ground/openpilotgcs/src/libs/utils/styledbar.cpp @@ -28,13 +28,8 @@ #include "styledbar.h" -#include "stylehelper.h" - -#include -#include -#include -#include -#include +#include +#include using namespace Utils; @@ -43,6 +38,7 @@ StyledBar::StyledBar(QWidget *parent) { setProperty("panelwidget", true); setProperty("panelwidget_singlerow", true); + setProperty("lightColored", false); } void StyledBar::setSingleRow(bool singleRow) @@ -55,12 +51,22 @@ bool StyledBar::isSingleRow() const return property("panelwidget_singlerow").toBool(); } +void StyledBar::setLightColored(bool lightColored) +{ + setProperty("lightColored", lightColored); +} + +bool StyledBar::isLightColored() const +{ + return property("lightColored").toBool(); +} + void StyledBar::paintEvent(QPaintEvent *event) { Q_UNUSED(event) QPainter painter(this); QStyleOption option; - option.rect = rect(); + option.rect = rect(); option.state = QStyle::State_Horizontal; style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this); } @@ -76,8 +82,8 @@ void StyledSeparator::paintEvent(QPaintEvent *event) Q_UNUSED(event) QPainter painter(this); QStyleOption option; - option.rect = rect(); - option.state = QStyle::State_Horizontal; + option.rect = rect(); + option.state = QStyle::State_Horizontal; option.palette = palette(); style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &option, &painter, this); } diff --git a/ground/openpilotgcs/src/libs/utils/styledbar.h b/ground/openpilotgcs/src/libs/utils/styledbar.h index e564eb1b6..17f065810 100644 --- a/ground/openpilotgcs/src/libs/utils/styledbar.h +++ b/ground/openpilotgcs/src/libs/utils/styledbar.h @@ -31,25 +31,34 @@ #include "utils_global.h" -#include +#include namespace Utils { -class QTCREATOR_UTILS_EXPORT StyledBar : public QWidget { + +class QTCREATOR_UTILS_EXPORT StyledBar : public QWidget +{ Q_OBJECT public: StyledBar(QWidget *parent = 0); void setSingleRow(bool singleRow); bool isSingleRow() const; + + void setLightColored(bool lightColored); + bool isLightColored() const; + protected: void paintEvent(QPaintEvent *event); }; -class QTCREATOR_UTILS_EXPORT StyledSeparator : public QWidget { +class QTCREATOR_UTILS_EXPORT StyledSeparator : public QWidget +{ + Q_OBJECT public: StyledSeparator(QWidget *parent = 0); protected: void paintEvent(QPaintEvent *event); }; + } // Utils #endif // STYLEDBAR_H diff --git a/ground/openpilotgcs/src/libs/utils/stylehelper.cpp b/ground/openpilotgcs/src/libs/utils/stylehelper.cpp index 5b22e39c5..9b49ab00c 100644 --- a/ground/openpilotgcs/src/libs/utils/stylehelper.cpp +++ b/ground/openpilotgcs/src/libs/utils/stylehelper.cpp @@ -28,36 +28,36 @@ #include "stylehelper.h" -#include -#include -#include -#include -#include -#include +#include "hostosinfo.h" + +#include +#include +#include +#include +#include // Clamps float color values within (0, 255) static int clamp(float x) { const int val = x > 255 ? 255 : static_cast(x); - return val < 0 ? 0 : val; } // Clamps float color values within (0, 255) /* - static int range(float x, int min, int max) - { +static int range(float x, int min, int max) +{ int val = x > max ? max : x; return val < min ? min : val; - } - */ +} +*/ namespace Utils { + QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor) { const int maxFactor = 100; QColor tmp = colorA; - tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); @@ -66,19 +66,12 @@ QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int qreal StyleHelper::sidebarFontSize() { -#if defined(Q_WS_MAC) - return 9; - -#else - return 7.5; - -#endif + return HostOsInfo::isMacHost() ? 10 : 7.5; } QPalette StyleHelper::sidebarFontPalette(const QPalette &original) { QPalette palette = original; - palette.setColor(QPalette::Active, QPalette::Text, panelTextColor()); palette.setColor(QPalette::Active, QPalette::WindowText, panelTextColor()); palette.setColor(QPalette::Inactive, QPalette::Text, panelTextColor().darker()); @@ -86,141 +79,176 @@ QPalette StyleHelper::sidebarFontPalette(const QPalette &original) return palette; } -QColor StyleHelper::panelTextColor() +QColor StyleHelper::panelTextColor(bool lightColored) { - // qApp->palette().highlightedText().color(); - return Qt::white; + //qApp->palette().highlightedText().color(); + if (!lightColored) + return Qt::white; + else + return Qt::black; } -QColor StyleHelper::m_baseColor(0x666666); +// Invalid by default, setBaseColor needs to be called at least once +QColor StyleHelper::m_baseColor; +QColor StyleHelper::m_requestedBaseColor; -QColor StyleHelper::baseColor() +QColor StyleHelper::baseColor(bool lightColored) { - return m_baseColor; + if (!lightColored) + return m_baseColor; + else + return m_baseColor.lighter(230); } -QColor StyleHelper::highlightColor() +QColor StyleHelper::highlightColor(bool lightColored) { - QColor result = baseColor(); - - result.setHsv(result.hue(), + QColor result = baseColor(lightColored); + if (!lightColored) + result.setHsv(result.hue(), clamp(result.saturation()), clamp(result.value() * 1.16)); + else + result.setHsv(result.hue(), + clamp(result.saturation()), + clamp(result.value() * 1.06)); return result; } -QColor StyleHelper::shadowColor() +QColor StyleHelper::shadowColor(bool lightColored) { - QColor result = baseColor(); - + QColor result = baseColor(lightColored); result.setHsv(result.hue(), clamp(result.saturation() * 1.1), clamp(result.value() * 0.70)); return result; } -QColor StyleHelper::borderColor() +QColor StyleHelper::borderColor(bool lightColored) { - QColor result = baseColor(); - + QColor result = baseColor(lightColored); result.setHsv(result.hue(), result.saturation(), result.value() / 2); return result; } -void StyleHelper::setBaseColor(const QColor &color) +// We try to ensure that the actual color used are within +// reasonalbe bounds while generating the actual baseColor +// from the users request. +void StyleHelper::setBaseColor(const QColor &newcolor) { + m_requestedBaseColor = newcolor; + + QColor color; + color.setHsv(newcolor.hue(), + newcolor.saturation() * 0.7, + 64 + newcolor.value() / 3); + if (color.isValid() && color != m_baseColor) { m_baseColor = color; - foreach(QWidget * w, QApplication::topLevelWidgets()) - w->update(); + foreach (QWidget *w, QApplication::topLevelWidgets()) + w->update(); } } -static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect) +static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored) { - QColor base = StyleHelper::baseColor(); + QColor highlight = StyleHelper::highlightColor(lightColored); + QColor shadow = StyleHelper::shadowColor(lightColored); QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); - - grad.setColorAt(0, StyleHelper::highlightColor()); - grad.setColorAt(0.301, base); - grad.setColorAt(1, StyleHelper::shadowColor()); + grad.setColorAt(0, highlight.lighter(117)); + grad.setColorAt(1, shadow.darker(109)); p->fillRect(rect, grad); QColor light(255, 255, 255, 80); p->setPen(light); p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); + QColor dark(0, 0, 0, 90); + p->setPen(dark); + p->drawLine(rect.topLeft(), rect.bottomLeft()); } -void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) +void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) { if (StyleHelper::usePixmapCache()) { QString key; + QColor keyColor = baseColor(lightColored); key.sprintf("mh_vertical %d %d %d %d %d", - spanRect.width(), spanRect.height(), clipRect.width(), - clipRect.height(), StyleHelper::baseColor().rgb());; + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), keyColor.rgb());; QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { pixmap = QPixmap(clipRect.size()); QPainter p(&pixmap); QRect rect(0, 0, clipRect.width(), clipRect.height()); - verticalGradientHelper(&p, spanRect, rect); + verticalGradientHelper(&p, spanRect, rect, lightColored); p.end(); QPixmapCache::insert(key, pixmap); } painter->drawPixmap(clipRect.topLeft(), pixmap); } else { - verticalGradientHelper(painter, spanRect, clipRect); + verticalGradientHelper(painter, spanRect, clipRect, lightColored); } } static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const - QRect &rect) +QRect &rect, bool lightColored) { - QColor base = StyleHelper::baseColor(); - QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); + if (lightColored) { + QLinearGradient shadowGradient(rect.topLeft(), rect.bottomLeft()); + shadowGradient.setColorAt(0, 0xf0f0f0); + shadowGradient.setColorAt(1, 0xcfcfcf); + p->fillRect(rect, shadowGradient); + return; + } - grad.setColorAt(0, StyleHelper::highlightColor().lighter(120)); + QColor base = StyleHelper::baseColor(lightColored); + QColor highlight = StyleHelper::highlightColor(lightColored); + QColor shadow = StyleHelper::shadowColor(lightColored); + QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); + grad.setColorAt(0, highlight.lighter(120)); if (rect.height() == StyleHelper::navigationWidgetHeight()) { - grad.setColorAt(0.4, StyleHelper::highlightColor()); + grad.setColorAt(0.4, highlight); grad.setColorAt(0.401, base); } - grad.setColorAt(1, StyleHelper::shadowColor()); + grad.setColorAt(1, shadow); p->fillRect(rect, grad); QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); - shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); - QColor highlight = StyleHelper::highlightColor().lighter(130); - highlight.setAlpha(100); - shadowGradient.setColorAt(0.7, highlight); - shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); + shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); + QColor lighterHighlight; + lighterHighlight = highlight.lighter(130); + lighterHighlight.setAlpha(100); + shadowGradient.setColorAt(0.7, lighterHighlight); + shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); p->fillRect(rect, shadowGradient); } -void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) +void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) { if (StyleHelper::usePixmapCache()) { QString key; - key.sprintf("mh_horizontal %d %d %d %d %d", - spanRect.width(), spanRect.height(), clipRect.width(), - clipRect.height(), StyleHelper::baseColor().rgb()); + QColor keyColor = baseColor(lightColored); + key.sprintf("mh_horizontal %d %d %d %d %d %d", + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), keyColor.rgb(), spanRect.x()); QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { pixmap = QPixmap(clipRect.size()); QPainter p(&pixmap); QRect rect = QRect(0, 0, clipRect.width(), clipRect.height()); - horizontalGradientHelper(&p, spanRect, rect); + horizontalGradientHelper(&p, spanRect, rect, lightColored); p.end(); QPixmapCache::insert(key, pixmap); } painter->drawPixmap(clipRect.topLeft(), pixmap); + } else { - horizontalGradientHelper(painter, spanRect, clipRect); + horizontalGradientHelper(painter, spanRect, clipRect, lightColored); } } @@ -228,19 +256,96 @@ static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect & { QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft()); QColor menuColor = StyleHelper::mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25); - grad.setColorAt(0, menuColor.lighter(112)); grad.setColorAt(1, menuColor); p->fillRect(rect, grad); } +void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option) +{ + // From windowsstyle but modified to enable AA + if (option->rect.width() <= 1 || option->rect.height() <= 1) + return; + + QRect r = option->rect; + int size = qMin(r.height(), r.width()); + QPixmap pixmap; + QString pixmapName; + pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld", + "$qt_ia", + uint(option->state), element, + size, option->palette.cacheKey()); + if (!QPixmapCache::find(pixmapName, pixmap)) { + int border = size/5; + int sqsize = 2*(size/2); + QImage image(sqsize, sqsize, QImage::Format_ARGB32); + image.fill(Qt::transparent); + QPainter imagePainter(&image); + imagePainter.setRenderHint(QPainter::Antialiasing, true); + imagePainter.translate(0.5, 0.5); + QPolygon a; + switch (element) { + case QStyle::PE_IndicatorArrowUp: + a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); + break; + case QStyle::PE_IndicatorArrowDown: + a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); + break; + case QStyle::PE_IndicatorArrowRight: + a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + break; + case QStyle::PE_IndicatorArrowLeft: + a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + break; + default: + break; + } + + int bsx = 0; + int bsy = 0; + + if (option->state & QStyle::State_Sunken) { + bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); + bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical); + } + + QRect bounds = a.boundingRect(); + int sx = sqsize / 2 - bounds.center().x() - 1; + int sy = sqsize / 2 - bounds.center().y() - 1; + imagePainter.translate(sx + bsx, sy + bsy); + + if (!(option->state & QStyle::State_Enabled)) { + QColor foreGround(150, 150, 150, 150); + imagePainter.setBrush(option->palette.mid().color()); + imagePainter.setPen(option->palette.mid().color()); + } else { + QColor shadow(0, 0, 0, 100); + imagePainter.translate(0, 1); + imagePainter.setPen(shadow); + imagePainter.setBrush(shadow); + QColor foreGround(255, 255, 255, 210); + imagePainter.drawPolygon(a); + imagePainter.translate(0, -1); + imagePainter.setPen(foreGround); + imagePainter.setBrush(foreGround); + } + imagePainter.drawPolygon(a); + imagePainter.end(); + pixmap = QPixmap::fromImage(image); + QPixmapCache::insert(pixmapName, pixmap); + } + int xOffset = r.x() + (r.width() - size)/2; + int yOffset = r.y() + (r.height() - size)/2; + painter->drawPixmap(xOffset, yOffset, pixmap); +} + void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) { if (StyleHelper::usePixmapCache()) { QString key; key.sprintf("mh_menu %d %d %d %d %d", - spanRect.width(), spanRect.height(), clipRect.width(), - clipRect.height(), StyleHelper::baseColor().rgb()); + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), StyleHelper::baseColor().rgb()); QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { @@ -257,4 +362,170 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q menuGradientHelper(painter, spanRect, clipRect); } } + +static qreal pixmapDevicePixelRatio(const QPixmap &pixmap) +{ +#if QT_VERSION > 0x050000 + return pixmap.devicePixelRatio(); +#else + Q_UNUSED(pixmap); + return 1.0; +#endif +} + +// Draws a cached pixmap with shadow +void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, + QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset) +{ + QPixmap cache; + QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); + + if (!QPixmapCache::find(pixmapName, cache)) { + // High-dpi support: The in parameters (rect, radius, offset) are in + // device-independent pixels. The call to QIcon::pixmap() below might + // return a high-dpi pixmap, which will in that case have a devicePixelRatio + // different than 1. The shadow drawing caluculations are done in device + // pixels. + QPixmap px = icon.pixmap(rect.size()); + int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px)); + int radius = dipRadius * devicePixelRatio; + QPoint offset = dipOffset * devicePixelRatio; + cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); + cache.fill(Qt::transparent); + + QPainter cachePainter(&cache); + if (iconMode == QIcon::Disabled) { + QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); + for (int y=0; y 0x050000 + cache.setDevicePixelRatio(devicePixelRatio); +#endif + QPixmapCache::insert(pixmapName, cache); + } + + QRect targetRect = cache.rect(); + targetRect.setSize(targetRect.size() / pixmapDevicePixelRatio(cache)); + targetRect.moveCenter(rect.center() - dipOffset); + p->drawPixmap(targetRect, cache); +} + +// Draws a CSS-like border image where the defined borders are not stretched +void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect, + int left, int top, int right, int bottom) +{ + QSize size = img.size(); + if (top > 0) { //top + painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img, + QRect(left, 0, size.width() -right - left, top)); + if (left > 0) //top-left + painter->drawImage(QRect(rect.left(), rect.top(), left, top), img, + QRect(0, 0, left, top)); + if (right > 0) //top-right + painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img, + QRect(size.width() - right, 0, right, top)); + } + //left + if (left > 0) + painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img, + QRect(0, top, left, size.height() - bottom - top)); + //center + painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, + rect.height() - bottom - top), img, + QRect(left, top, size.width() -right -left, + size.height() - bottom - top)); + if (right > 0) //right + painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img, + QRect(size.width() - right, top, right, size.height() - bottom - top)); + if (bottom > 0) { //bottom + painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom, + rect.width() - right - left, bottom), img, + QRect(left, size.height() - bottom, + size.width() - right - left, bottom)); + if (left > 0) //bottom-left + painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img, + QRect(0, size.height() - bottom, left, bottom)); + if (right > 0) //bottom-right + painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img, + QRect(size.width() - right, size.height() - bottom, right, bottom)); + } +} + +// Tints an image with tintColor, while preserving alpha and lightness +void StyleHelper::tintImage(QImage &img, const QColor &tintColor) +{ + QPainter p(&img); + p.setCompositionMode(QPainter::CompositionMode_Screen); + + for (int x = 0; x < img.width(); ++x) { + for (int y = 0; y < img.height(); ++y) { + QRgb rgbColor = img.pixel(x, y); + int alpha = qAlpha(rgbColor); + QColor c = QColor(rgbColor); + + if (alpha > 0) { + c.toHsl(); + qreal l = c.lightnessF(); + QColor newColor = QColor::fromHslF(tintColor.hslHueF(), tintColor.hslSaturationF(), l); + newColor.setAlpha(alpha); + img.setPixel(x, y, newColor.rgba()); + } + } + } +} + +QLinearGradient StyleHelper::statusBarGradient(const QRect &statusBarRect) +{ + QLinearGradient grad(statusBarRect.topLeft(), QPoint(statusBarRect.center().x(), statusBarRect.bottom())); + QColor startColor = shadowColor().darker(164); + QColor endColor = baseColor().darker(130); + grad.setColorAt(0, startColor); + grad.setColorAt(1, endColor); + return grad; +} + } // namespace Utils diff --git a/ground/openpilotgcs/src/libs/utils/stylehelper.h b/ground/openpilotgcs/src/libs/utils/stylehelper.h index fb8384555..0f8c75a35 100644 --- a/ground/openpilotgcs/src/libs/utils/stylehelper.h +++ b/ground/openpilotgcs/src/libs/utils/stylehelper.h @@ -31,55 +31,69 @@ #include "utils_global.h" -#include +#include QT_BEGIN_NAMESPACE class QPalette; class QPainter; class QRect; +// Note, this is exported but in a private header as qtopengl depends on it. +// We should consider adding this as a public helper function. +void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0); QT_END_NAMESPACE // Helper class holding all custom color values namespace Utils { -class QTCREATOR_UTILS_EXPORT StyleHelper { +class QTCREATOR_UTILS_EXPORT StyleHelper +{ public: + static const unsigned int DEFAULT_BASE_COLOR = 0x666666; + static const int progressFadeAnimationDuration = 600; + // Height of the project explorer navigation bar - static int navigationWidgetHeight() - { - return 24; - } + static int navigationWidgetHeight() { return 24; } static qreal sidebarFontSize(); static QPalette sidebarFontPalette(const QPalette &original); // This is our color table, all colors derive from baseColor - static QColor baseColor(); - static QColor panelTextColor(); - static QColor highlightColor(); - static QColor shadowColor(); - static QColor borderColor(); - static QColor buttonTextColor() - { - return QColor(0x4c4c4c); - } + static QColor requestedBaseColor() { return m_requestedBaseColor; } + static QColor baseColor(bool lightColored = false); + static QColor panelTextColor(bool lightColored = false); + static QColor highlightColor(bool lightColored = false); + static QColor shadowColor(bool lightColored = false); + static QColor borderColor(bool lightColored = false); + static QColor buttonTextColor() { return QColor(0x4c4c4c); } static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50); + static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); } + static QColor sidebarShadow() { return QColor(0, 0, 0, 40); } + // Sets the base color and makes sure all top level widgets are updated static void setBaseColor(const QColor &color); - // Gradients used for panels - static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); - static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); - static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); + // Draws a shaded anti-aliased arrow + static void drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option); - // Pixmap cache should only be enabled for X11 due to slow gradients - static bool usePixmapCache() - { - return true; - } + // Gradients used for panels + static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); + static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); + static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); + static bool usePixmapCache() { return true; } + + static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, + int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130), + const QPoint &dipOffset = QPoint(1, -2)); + static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect, + int left = 0, int top = 0, int right = 0, int bottom = 0); + + static void tintImage(QImage &img, const QColor &tintColor); + static QLinearGradient statusBarGradient(const QRect &statusBarRect); private: static QColor m_baseColor; + static QColor m_requestedBaseColor; }; + } // namespace Utils #endif // STYLEHELPER_H diff --git a/ground/openpilotgcs/src/libs/utils/submiteditorwidget.cpp b/ground/openpilotgcs/src/libs/utils/submiteditorwidget.cpp index 76131e276..2551715b8 100644 --- a/ground/openpilotgcs/src/libs/utils/submiteditorwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/submiteditorwidget.cpp @@ -34,11 +34,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include enum { debug = 0 }; enum { defaultLineWidth = 72 }; diff --git a/ground/openpilotgcs/src/libs/utils/submiteditorwidget.h b/ground/openpilotgcs/src/libs/utils/submiteditorwidget.h index 61c639b7e..3782cf49c 100644 --- a/ground/openpilotgcs/src/libs/utils/submiteditorwidget.h +++ b/ground/openpilotgcs/src/libs/utils/submiteditorwidget.h @@ -31,8 +31,8 @@ #include "utils_global.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE class QTextEdit; diff --git a/ground/openpilotgcs/src/libs/utils/submitfieldwidget.cpp b/ground/openpilotgcs/src/libs/utils/submitfieldwidget.cpp index 3e39238b2..902701a91 100644 --- a/ground/openpilotgcs/src/libs/utils/submitfieldwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/submitfieldwidget.cpp @@ -28,14 +28,14 @@ #include "submitfieldwidget.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/ground/openpilotgcs/src/libs/utils/submitfieldwidget.h b/ground/openpilotgcs/src/libs/utils/submitfieldwidget.h index 8bc912c27..4dc3ea394 100644 --- a/ground/openpilotgcs/src/libs/utils/submitfieldwidget.h +++ b/ground/openpilotgcs/src/libs/utils/submitfieldwidget.h @@ -31,7 +31,7 @@ #include "utils_global.h" -#include +#include QT_BEGIN_NAMESPACE class QCompleter; diff --git a/ground/openpilotgcs/src/libs/utils/synchronousprocess.cpp b/ground/openpilotgcs/src/libs/utils/synchronousprocess.cpp index 02a9dfff9..0bbef1d05 100644 --- a/ground/openpilotgcs/src/libs/utils/synchronousprocess.cpp +++ b/ground/openpilotgcs/src/libs/utils/synchronousprocess.cpp @@ -35,7 +35,7 @@ #include #include -#include +#include #include diff --git a/ground/openpilotgcs/src/libs/utils/treewidgetcolumnstretcher.cpp b/ground/openpilotgcs/src/libs/utils/treewidgetcolumnstretcher.cpp index 6efdd0d48..51ee4d07f 100644 --- a/ground/openpilotgcs/src/libs/utils/treewidgetcolumnstretcher.cpp +++ b/ground/openpilotgcs/src/libs/utils/treewidgetcolumnstretcher.cpp @@ -27,9 +27,9 @@ */ #include "treewidgetcolumnstretcher.h" -#include -#include -#include +#include +#include +#include using namespace Utils; TreeWidgetColumnStretcher::TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch) @@ -46,16 +46,16 @@ bool TreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev) if (ev->type() == QEvent::Show) { QHeaderView *hv = qobject_cast(obj); for (int i = 0; i < hv->count(); ++i) { - hv->setResizeMode(i, QHeaderView::Interactive); + hv->setSectionResizeMode(i, QHeaderView::Interactive); } } else if (ev->type() == QEvent::Hide) { QHeaderView *hv = qobject_cast(obj); for (int i = 0; i < hv->count(); ++i) { - hv->setResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); + hv->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); } } else if (ev->type() == QEvent::Resize) { QHeaderView *hv = qobject_cast(obj); - if (hv->resizeMode(m_columnToStretch) == QHeaderView::Interactive) { + if (hv->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive) { QResizeEvent *re = static_cast(ev); int diff = re->size().width() - re->oldSize().width(); hv->resizeSection(m_columnToStretch, qMax(32, hv->sectionSize(1) + diff)); diff --git a/ground/openpilotgcs/src/libs/utils/uncommentselection.cpp b/ground/openpilotgcs/src/libs/utils/uncommentselection.cpp index 1c3669f4c..f58c62435 100644 --- a/ground/openpilotgcs/src/libs/utils/uncommentselection.cpp +++ b/ground/openpilotgcs/src/libs/utils/uncommentselection.cpp @@ -27,10 +27,10 @@ */ #include "uncommentselection.h" -#include -#include -#include -#include +#include +#include +#include +#include void Utils::unCommentSelection(QPlainTextEdit *edit) { diff --git a/ground/openpilotgcs/src/libs/utils/utils.pro b/ground/openpilotgcs/src/libs/utils/utils.pro index 963675a14..aff6db1e0 100644 --- a/ground/openpilotgcs/src/libs/utils/utils.pro +++ b/ground/openpilotgcs/src/libs/utils/utils.pro @@ -6,7 +6,8 @@ QT += gui \ xml \ svg \ opengl \ - declarative + declarative \ + widgets DEFINES += QTCREATOR_UTILS_LIB @@ -51,9 +52,9 @@ SOURCES += reloadpromptutils.cpp \ homelocationutil.cpp \ mytabbedstackwidget.cpp \ mytabwidget.cpp \ - mylistwidget.cpp \ cachedsvgitem.cpp \ - svgimageprovider.cpp + svgimageprovider.cpp \ + hostosinfo.cpp SOURCES += xmlconfig.cpp @@ -108,9 +109,9 @@ HEADERS += utils_global.h \ homelocationutil.h \ mytabbedstackwidget.h \ mytabwidget.h \ - mylistwidget.h \ cachedsvgitem.h \ - svgimageprovider.h + svgimageprovider.h \ + hostosinfo.h HEADERS += xmlconfig.h diff --git a/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.cpp b/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.cpp index 723316038..f5e72a74d 100644 --- a/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.cpp @@ -28,10 +28,10 @@ #include "welcomemodetreewidget.h" -#include -#include -#include -#include +#include +#include +#include +#include namespace Utils { void WelcomeModeLabel::setStyledText(const QString &text) diff --git a/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.h b/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.h index 67374c469..8805cf6c2 100644 --- a/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.h +++ b/ground/openpilotgcs/src/libs/utils/welcomemodetreewidget.h @@ -31,8 +31,8 @@ #include "utils_global.h" -#include -#include +#include +#include namespace Utils { struct WelcomeModeTreeWidgetPrivate; diff --git a/ground/openpilotgcs/src/libs/utils/xmlconfig.cpp b/ground/openpilotgcs/src/libs/utils/xmlconfig.cpp index 3170cd6ca..dc349e726 100644 --- a/ground/openpilotgcs/src/libs/utils/xmlconfig.cpp +++ b/ground/openpilotgcs/src/libs/utils/xmlconfig.cpp @@ -88,7 +88,7 @@ void XmlConfig::handleNode(QDomElement *node, QSettings::SettingsMap &map, QStri // Xml tags are restrictive with allowed characters, // so we urlencode and replace % with __PCT__ on file nodeName = nodeName.replace("__PCT__", "%"); - nodeName = QUrl::fromPercentEncoding(nodeName.toAscii()); + nodeName = QUrl::fromPercentEncoding(nodeName.toLatin1()); if (nodeName == XmlConfig::rootName) { ;