mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
[OP-835] Qt 5.1.0 - migrated GCS libs/util
This commit is contained in:
parent
706c371ccc
commit
2e02843e59
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace Utils {
|
||||
struct BaseValidatingLineEditPrivate;
|
||||
|
@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include "cachedsvgitem.h"
|
||||
#include <QGLContext>
|
||||
#include <QDebug>
|
||||
|
||||
#ifndef GL_CLAMP_TO_EDGE
|
||||
|
@ -26,7 +26,8 @@
|
||||
#define CACHEDSVGITEM_H
|
||||
|
||||
#include <QGraphicsSvgItem>
|
||||
#include <QGLContext>
|
||||
#include <QtOpenGL>
|
||||
#include <QtOpenGL/QGLContext>
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "checkablemessagebox.h"
|
||||
#include "ui_checkablemessagebox.h"
|
||||
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QPushButton>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
namespace Utils {
|
||||
|
@ -31,9 +31,9 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
#include <QDialog>
|
||||
|
||||
namespace Utils {
|
||||
struct CheckableMessageBoxPrivate;
|
||||
|
@ -29,8 +29,8 @@
|
||||
#ifndef DETAILSBUTTON_H
|
||||
#define DETAILSBUTTON_H
|
||||
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
|
@ -29,11 +29,11 @@
|
||||
#include "detailswidget.h"
|
||||
#include "detailsbutton.h"
|
||||
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QtCore/QStack>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLabel;
|
||||
|
@ -31,10 +31,10 @@
|
||||
#include <QtCore/QEvent>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QLabel>
|
||||
|
||||
enum { margin = 6 };
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace Utils {
|
||||
class FancyLineEditPrivate;
|
||||
|
@ -28,34 +28,89 @@
|
||||
|
||||
#include "fancymainwindow.h"
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QDockWidget>
|
||||
#include <QtCore/QSettings>
|
||||
#include "qtcassert.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QDockWidget>
|
||||
#include <QSettings>
|
||||
|
||||
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<QDockWidget *>(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<QDockWidget *>(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<QDockWidget *>(sender()));
|
||||
updateDockWidget(qobject_cast<QDockWidget*>(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<QString, QVariant> 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<QString, QVariant> FancyMainWindow::saveSettings() const
|
||||
{
|
||||
QHash<QString, QVariant> 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<QString, QVariant> &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<QDockWidget *> FancyMainWindow::dockWidgets() const
|
||||
{
|
||||
return findChildren<QDockWidget *>();
|
||||
}
|
||||
|
||||
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<QAction *> actions;
|
||||
QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
|
||||
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
|
||||
|
@ -31,46 +31,63 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QMainWindow>
|
||||
|
||||
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<QDockWidget *> dockWidgets() const
|
||||
{
|
||||
return m_dockWidgets;
|
||||
}
|
||||
QList<QDockWidget *> 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<QString, QVariant> saveSettings() const;
|
||||
void restoreSettings(const QHash<QString, QVariant> &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<QDockWidget *> m_dockWidgets;
|
||||
QList<bool> m_dockWidgetActiveState;
|
||||
bool m_locked;
|
||||
bool m_handleDockVisibilityChanges; // todo
|
||||
FancyMainWindowPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#endif // FANCYMAINWINDOW_H
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFutureInterface>
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QtCore/QRegExp>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QFuture>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtGui/QTextDocument>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace Utils {
|
||||
class QTCREATOR_UTILS_EXPORT FileSearchResult {
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "filewizarddialog.h"
|
||||
#include "filewizardpage.h"
|
||||
|
||||
#include <QtGui/QAbstractButton>
|
||||
#include <QAbstractButton>
|
||||
|
||||
namespace Utils {
|
||||
FileWizardDialog::FileWizardDialog(QWidget *parent) :
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWizard>
|
||||
#include <QWizard>
|
||||
|
||||
namespace Utils {
|
||||
class FileWizardPage;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWizardPage>
|
||||
#include <QWizardPage>
|
||||
|
||||
namespace Utils {
|
||||
struct FileWizardPagePrivate;
|
||||
|
@ -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 <windows.h>
|
||||
#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
|
||||
}
|
||||
|
110
ground/openpilotgcs/src/libs/utils/hostosinfo.h
Normal file
110
ground/openpilotgcs/src/libs/utils/hostosinfo.h
Normal file
@ -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 <QString>
|
||||
|
||||
#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
|
@ -30,7 +30,7 @@
|
||||
#define LINECOLUMNLABEL_H
|
||||
|
||||
#include "utils_global.h"
|
||||
#include <QtGui/QLabel>
|
||||
#include <QLabel>
|
||||
|
||||
namespace Utils {
|
||||
/* A label suitable for displaying cursor positions, etc. with a fixed
|
||||
|
@ -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 <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
|
@ -26,9 +26,9 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "mytabbedstackwidget.h"
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -29,13 +29,10 @@
|
||||
#ifndef MYTABBEDSTACKWIDGET_H
|
||||
#define MYTABBEDSTACKWIDGET_H
|
||||
|
||||
#include "utils/mylistwidget.h"
|
||||
#include <QtGui/QStackedWidget>
|
||||
#include <QListWidget>
|
||||
#include <QStackedWidget>
|
||||
#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;
|
||||
|
@ -26,7 +26,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "mytabwidget.h"
|
||||
#include <QtGui/QTabBar>
|
||||
#include <QTabBar>
|
||||
|
||||
MyTabWidget::MyTabWidget(QWidget *parent)
|
||||
: QTabWidget(parent)
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QTabWidget>
|
||||
#include <QTabWidget>
|
||||
|
||||
/*
|
||||
* MyTabWidget is a plain QTabWidget with the addition of the signal
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include <utils/filewizardpage.h>
|
||||
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QDir>
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QStringList;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QAction>
|
||||
|
||||
namespace Utils {
|
||||
/* ParameterAction: Intended for actions that act on a 'current',
|
||||
|
@ -36,12 +36,12 @@
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <QtGui/QDesktopServices>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
|
||||
/*static*/ const char *const Utils::PathChooser::browseButtonLabel =
|
||||
#ifdef Q_WS_MAC
|
||||
@ -280,7 +280,7 @@ QString PathChooser::homePath()
|
||||
// Return 'users/<name>/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();
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QAbstractButton>
|
||||
#include <QWidget>
|
||||
#include <QAbstractButton>
|
||||
|
||||
namespace Utils {
|
||||
struct PathChooserPrivate;
|
||||
|
@ -28,16 +28,16 @@
|
||||
|
||||
#include "pathlisteditor.h"
|
||||
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QTextCursor>
|
||||
#include <QtGui/QTextBlock>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QAction>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QToolButton>
|
||||
#include <QSpacerItem>
|
||||
#include <QFileDialog>
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlock>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtCore/QMimeData>
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QWidget>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "utils_global.h"
|
||||
#include "../extensionsystem/pluginmanager.h"
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
namespace Utils {
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "filewizardpage.h"
|
||||
#include "ui_projectintropage.h"
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QMessageBox>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWizardPage>
|
||||
#include <QWizardPage>
|
||||
|
||||
namespace Utils {
|
||||
struct ProjectIntroPagePrivate;
|
||||
|
@ -29,10 +29,11 @@
|
||||
#include "qtcolorbutton.h"
|
||||
|
||||
#include <QtCore/QMimeData>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QColorDialog>
|
||||
#include <QtGui/QDragEnterEvent>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QColorDialog>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDrag>
|
||||
#include <QPainter>
|
||||
|
||||
namespace Utils {
|
||||
class QtColorButtonPrivate {
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace Utils {
|
||||
class QTCREATOR_UTILS_EXPORT QtColorButton : public QToolButton {
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include "reloadpromptutils.h"
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QMessageBox>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
|
@ -34,13 +34,13 @@
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <QtGui/QAbstractButton>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QActionGroup>
|
||||
#include <QtGui/QCheckBox>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QRadioButton>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QAbstractButton>
|
||||
#include <QAction>
|
||||
#include <QActionGroup>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QRadioButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
|
||||
using namespace Utils;
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QAction>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
|
@ -28,13 +28,8 @@
|
||||
|
||||
#include "styledbar.h"
|
||||
|
||||
#include "stylehelper.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPixmapCache>
|
||||
#include <QtGui/QStyle>
|
||||
#include <QtGui/QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -31,25 +31,34 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QWidget>
|
||||
|
||||
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
|
||||
|
@ -28,36 +28,36 @@
|
||||
|
||||
#include "stylehelper.h"
|
||||
|
||||
#include <QtGui/QPixmapCache>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtCore/QRect>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QPalette>
|
||||
#include "hostosinfo.h"
|
||||
|
||||
#include <QPixmapCache>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QStyleOption>
|
||||
#include <qmath.h>
|
||||
|
||||
// Clamps float color values within (0, 255)
|
||||
static int clamp(float x)
|
||||
{
|
||||
const int val = x > 255 ? 255 : static_cast<int>(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<im.height(); ++y) {
|
||||
QRgb *scanLine = (QRgb*)im.scanLine(y);
|
||||
for (int x=0; x<im.width(); ++x) {
|
||||
QRgb pixel = *scanLine;
|
||||
char intensity = qGray(pixel);
|
||||
*scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
|
||||
++scanLine;
|
||||
}
|
||||
}
|
||||
px = QPixmap::fromImage(im);
|
||||
}
|
||||
|
||||
// Draw shadow
|
||||
QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
|
||||
tmp.fill(Qt::transparent);
|
||||
|
||||
QPainter tmpPainter(&tmp);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
|
||||
tmpPainter.end();
|
||||
|
||||
// blur the alpha channel
|
||||
QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
blurred.fill(Qt::transparent);
|
||||
QPainter blurPainter(&blurred);
|
||||
qt_blurImage(&blurPainter, tmp, radius, false, true);
|
||||
blurPainter.end();
|
||||
|
||||
tmp = blurred;
|
||||
|
||||
// blacken the image...
|
||||
tmpPainter.begin(&tmp);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
tmpPainter.fillRect(tmp.rect(), color);
|
||||
tmpPainter.end();
|
||||
|
||||
tmpPainter.begin(&tmp);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
tmpPainter.fillRect(tmp.rect(), color);
|
||||
tmpPainter.end();
|
||||
|
||||
// draw the blurred drop shadow...
|
||||
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
|
||||
|
||||
// Draw the actual pixmap...
|
||||
cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px);
|
||||
#if QT_VERSION > 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
|
||||
|
@ -31,55 +31,69 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QColor>
|
||||
#include <QStyle>
|
||||
|
||||
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
|
||||
|
@ -34,11 +34,11 @@
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QPushButton>
|
||||
#include <QMenu>
|
||||
#include <QHBoxLayout>
|
||||
#include <QToolButton>
|
||||
#include <QSpacerItem>
|
||||
|
||||
enum { debug = 0 };
|
||||
enum { defaultLineWidth = 72 };
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QAbstractItemView>
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemView>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextEdit;
|
||||
|
@ -28,14 +28,14 @@
|
||||
|
||||
#include "submitfieldwidget.h"
|
||||
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QCompleter>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QToolBar>
|
||||
#include <QComboBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QCompleter>
|
||||
#include <QIcon>
|
||||
#include <QToolBar>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QDebug>
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCompleter;
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
*/
|
||||
|
||||
#include "treewidgetcolumnstretcher.h"
|
||||
#include <QtGui/QTreeWidget>
|
||||
#include <QtGui/QHideEvent>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QTreeWidget>
|
||||
#include <QHideEvent>
|
||||
#include <QHeaderView>
|
||||
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<QHeaderView *>(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<QHeaderView *>(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<QHeaderView *>(obj);
|
||||
if (hv->resizeMode(m_columnToStretch) == QHeaderView::Interactive) {
|
||||
if (hv->sectionResizeMode(m_columnToStretch) == QHeaderView::Interactive) {
|
||||
QResizeEvent *re = static_cast<QResizeEvent *>(ev);
|
||||
int diff = re->size().width() - re->oldSize().width();
|
||||
hv->resizeSection(m_columnToStretch, qMax(32, hv->sectionSize(1) + diff));
|
||||
|
@ -27,10 +27,10 @@
|
||||
*/
|
||||
|
||||
#include "uncommentselection.h"
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtGui/QTextCursor>
|
||||
#include <QtGui/QTextBlock>
|
||||
#include <QtGui/QTextDocument>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlock>
|
||||
#include <QTextDocument>
|
||||
|
||||
void Utils::unCommentSelection(QPlainTextEdit *edit)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -28,10 +28,10 @@
|
||||
|
||||
#include "welcomemodetreewidget.h"
|
||||
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QBoxLayout>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QAction>
|
||||
#include <QBoxLayout>
|
||||
#include <QHeaderView>
|
||||
|
||||
namespace Utils {
|
||||
void WelcomeModeLabel::setStyledText(const QString &text)
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtGui/QTreeWidget>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QTreeWidget>
|
||||
#include <QLabel>
|
||||
|
||||
namespace Utils {
|
||||
struct WelcomeModeTreeWidgetPrivate;
|
||||
|
@ -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) {
|
||||
;
|
||||
|
Loading…
x
Reference in New Issue
Block a user