forked from qt-creator/qt-creator
Make sure we add the toolchain only in case we have a valid madde.
Reviewed-by: ck
This commit is contained in:
242
src/plugins/help/openedviewerswidget.cpp
Normal file
242
src/plugins/help/openedviewerswidget.cpp
Normal file
@@ -0,0 +1,242 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "openedviewerswidget.h"
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpviewer.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
|
||||
using namespace Help::Internal;
|
||||
|
||||
OpenedViewersDelegate::OpenedViewersDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OpenedViewersDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
if ((QApplication::mouseButtons() & Qt::LeftButton) == 0)
|
||||
pressedIndex = QModelIndex();
|
||||
|
||||
QBrush brush = option.palette.alternateBase();
|
||||
if (index == pressedIndex)
|
||||
brush = option.palette.dark();
|
||||
|
||||
painter->fillRect(option.rect, brush);
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (index.column() == 1 && option.state & QStyle::State_MouseOver) {
|
||||
QIcon icon((option.state & QStyle::State_Selected)
|
||||
? ":/core/images/closebutton.png" : ":/core/images/darkclosebutton.png");
|
||||
|
||||
QRect iconRect(option.rect.right() - option.rect.height(),
|
||||
option.rect.top(), option.rect.height(), option.rect.height());
|
||||
|
||||
icon.paint(painter, iconRect, Qt::AlignRight | Qt::AlignVCenter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// OpenedViewersWidget
|
||||
|
||||
|
||||
OpenedViewersWidget::OpenedViewersWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_delegate(new OpenedViewersDelegate(this))
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
setFocusProxy(m_ui.viewerList);
|
||||
setWindowTitle(tr("Open Documents"));
|
||||
setWindowIcon(QIcon(Core::Constants::ICON_DIR));
|
||||
|
||||
m_ui.viewerList->installEventFilter(this);
|
||||
m_ui.viewerList->setItemDelegate(m_delegate);
|
||||
m_ui.viewerList->viewport()->setAttribute(Qt::WA_Hover);
|
||||
m_ui.viewerList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
m_ui.viewerList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
|
||||
m_model = new QStandardItemModel(0, 2, this);
|
||||
m_ui.viewerList->setModel(m_model);
|
||||
|
||||
m_ui.viewerList->header()->setResizeMode(1, QHeaderView::Fixed);
|
||||
m_ui.viewerList->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||
m_ui.viewerList->header()->resizeSection(1, 16);
|
||||
|
||||
CentralWidget *widget = CentralWidget::instance();
|
||||
connect(widget, SIGNAL(sourceChanged(QUrl)), this,
|
||||
SLOT(resetWidgetModel()));
|
||||
connect(widget, SIGNAL(currentViewerChanged(int)), this,
|
||||
SLOT(updateViewerWidgetModel(int)));
|
||||
connect(widget, SIGNAL(viewerAboutToBeRemoved(int)), this,
|
||||
SLOT(removeViewerFromWidgetModel(int)));
|
||||
|
||||
connect(m_ui.viewerList, SIGNAL(clicked(QModelIndex)), this,
|
||||
SLOT(handleClicked(QModelIndex)));
|
||||
connect(m_ui.viewerList, SIGNAL(pressed(QModelIndex)), this,
|
||||
SLOT(handlePressed(QModelIndex)));
|
||||
connect(m_ui.viewerList, SIGNAL(customContextMenuRequested(QPoint)), this,
|
||||
SLOT(contextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
OpenedViewersWidget::~OpenedViewersWidget()
|
||||
{
|
||||
}
|
||||
|
||||
bool OpenedViewersWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (obj == m_ui.viewerList && event->type() == QEvent::KeyPress
|
||||
&& m_ui.viewerList->currentIndex().isValid()) {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
|
||||
const int key = ke->key();
|
||||
if ((key == Qt::Key_Return || key == Qt::Key_Enter)
|
||||
&& ke->modifiers() == 0) {
|
||||
handlePressed(m_ui.viewerList->currentIndex());
|
||||
return true;
|
||||
} else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace)
|
||||
&& ke->modifiers() == 0) {
|
||||
handleClicked(m_ui.viewerList->currentIndex());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::resetWidgetModel()
|
||||
{
|
||||
m_model->clear();
|
||||
|
||||
int i = 0;
|
||||
CentralWidget *widget = CentralWidget::instance();
|
||||
QStandardItem *parentItem = m_model->invisibleRootItem();
|
||||
while (HelpViewer *viewer = widget->helpViewerAtIndex(i++)) {
|
||||
QList<QStandardItem*> list;
|
||||
list.append(new QStandardItem(viewer->documentTitle()));
|
||||
list.append(new QStandardItem());
|
||||
parentItem->appendRow(list);
|
||||
}
|
||||
|
||||
m_ui.viewerList->header()->setStretchLastSection(false);
|
||||
m_ui.viewerList->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||
m_ui.viewerList->header()->setResizeMode(1, QHeaderView::Fixed);
|
||||
m_ui.viewerList->header()->resizeSection(1, 16);
|
||||
m_ui.viewerList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
||||
int row = widget->indexOf(widget->currentHelpViewer());
|
||||
if (row >= 0)
|
||||
m_ui.viewerList->setCurrentIndex(m_model->index(row, 0));
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::updateViewerWidgetModel(int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
m_ui.viewerList->setCurrentIndex(m_model->index(index, 0));
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::removeViewerFromWidgetModel(int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
m_model->removeRow(index);
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::handleClicked(const QModelIndex &index)
|
||||
{
|
||||
if (index.isValid() && index.column() == 1) {
|
||||
// the funky close button
|
||||
CentralWidget::instance()->closeTab(index.row());
|
||||
|
||||
// work around a bug in itemviews where the delegate wouldn't get the
|
||||
// QStyle::State_MouseOver
|
||||
QPoint cursorPos = QCursor::pos();
|
||||
QWidget *vp = m_ui.viewerList->viewport();
|
||||
QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos),
|
||||
cursorPos, Qt::NoButton, 0, 0);
|
||||
QCoreApplication::sendEvent(vp, &e);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::handlePressed(const QModelIndex &index)
|
||||
{
|
||||
if (index.isValid()) {
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
CentralWidget::instance()->activateTab(index.row());
|
||||
break;
|
||||
|
||||
case 1:
|
||||
m_delegate->pressedIndex = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenedViewersWidget::contextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
const QModelIndex &index = m_ui.viewerList->indexAt(pos);
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
CentralWidget *widget = CentralWidget::instance();
|
||||
HelpViewer *viewer = widget->helpViewerAtIndex(index.row());
|
||||
if (widget->count() <= 1 || !viewer)
|
||||
return;
|
||||
|
||||
QMenu contextMenu;
|
||||
const QString &title = viewer->documentTitle();
|
||||
QAction *close = contextMenu.addAction(tr("Close %1").arg(title));
|
||||
QAction *closeOther = contextMenu.addAction(tr("Close All Except %1").arg(title));
|
||||
|
||||
if (QAction *action = contextMenu.exec(m_ui.viewerList->mapToGlobal(pos))) {
|
||||
if (action == closeOther) {
|
||||
int currentPage = widget->indexOf(viewer);
|
||||
for (int i = widget->count() - 1; i >= 0; --i) {
|
||||
viewer = widget->helpViewerAtIndex(i);
|
||||
if (i != currentPage && viewer) {
|
||||
widget->closeTab(i);
|
||||
if (i < currentPage)
|
||||
--currentPage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (action == close)
|
||||
widget->closeTab(index.row());
|
||||
}
|
||||
}
|
||||
81
src/plugins/help/openedviewerswidget.h
Normal file
81
src/plugins/help/openedviewerswidget.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef OPENEDVIEWERSWIDGET_H
|
||||
#define OPENEDVIEWERSWIDGET_H
|
||||
|
||||
#include <QtGui/QStyledItemDelegate>
|
||||
#include <QtGui/QStandardItemModel>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
#include "ui_openedviewerswidget.h"
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
class OpenedViewersDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OpenedViewersDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
mutable QModelIndex pressedIndex;
|
||||
};
|
||||
|
||||
class OpenedViewersWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OpenedViewersWidget(QWidget *parent = 0);
|
||||
~OpenedViewersWidget();
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private slots:
|
||||
void resetWidgetModel();
|
||||
void updateViewerWidgetModel(int index);
|
||||
void removeViewerFromWidgetModel(int index);
|
||||
|
||||
void handleClicked(const QModelIndex &index);
|
||||
void handlePressed(const QModelIndex &index);
|
||||
void contextMenuRequested(const QPoint &pos);
|
||||
|
||||
private:
|
||||
Ui::OpenedViewersWidget m_ui;
|
||||
QStandardItemModel *m_model;
|
||||
OpenedViewersDelegate *m_delegate;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Help
|
||||
|
||||
#endif // OPENEDVIEWERSWIDGET_H
|
||||
52
src/plugins/help/openedviewerswidget.ui
Normal file
52
src/plugins/help/openedviewerswidget.ui
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenedViewersWidget</class>
|
||||
<widget class="QWidget" name="OpenedViewersWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>263</width>
|
||||
<height>217</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="viewerList">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::ElideMiddle</enum>
|
||||
</property>
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="headerHidden">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -40,8 +40,11 @@
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMutexLocker>
|
||||
#include <QtCore/QTextStream>
|
||||
|
||||
#include <QtGui/QAction>
|
||||
|
||||
@@ -89,6 +92,30 @@ MaemoManager *MaemoManager::instance()
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
bool
|
||||
MaemoManager::isValidMaemoQtVersion(const Qt4ProjectManager::QtVersion *version) const
|
||||
{
|
||||
QString path = QDir::cleanPath(version->qmakeCommand());
|
||||
path = path.remove(QLatin1String("/bin/qmake" EXEC_SUFFIX));
|
||||
|
||||
QDir dir(path);
|
||||
dir.cdUp(); dir.cdUp();
|
||||
|
||||
QFile file(dir.absolutePath() + QLatin1String("/cache/madde.conf"));
|
||||
if (file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
const QString &target = path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
|
||||
QTextStream stream(&file);
|
||||
while (!stream.atEnd()) {
|
||||
const QString &line = stream.readLine().trimmed();
|
||||
if (line.startsWith(QLatin1String("target"))
|
||||
&& line.endsWith(target)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectExplorer::ToolChain*
|
||||
MaemoManager::maemoToolChain(const QtVersion *version) const
|
||||
{
|
||||
|
||||
@@ -66,6 +66,7 @@ class MaemoManager : public QObject
|
||||
public:
|
||||
static MaemoManager *instance();
|
||||
|
||||
bool isValidMaemoQtVersion(const Qt4ProjectManager::QtVersion *version) const;
|
||||
void addVersion(const Qt4ProjectManager::QtVersion *version) { Q_UNUSED(version); }
|
||||
ToolChain *maemoToolChain(const Qt4ProjectManager::QtVersion *version) const;
|
||||
|
||||
|
||||
@@ -36,12 +36,6 @@
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Qt4ProjectManager::Internal;
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#define EXEC_SUFFIX ".exe"
|
||||
#else
|
||||
#define EXEC_SUFFIX ""
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
const char *GCC_MAEMO_COMMAND = "arm-none-linux-gnueabi-gcc" EXEC_SUFFIX;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ namespace Qt4ProjectManager {
|
||||
class QtVersion;
|
||||
namespace Internal {
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#define EXEC_SUFFIX ".exe"
|
||||
#else
|
||||
#define EXEC_SUFFIX ""
|
||||
#endif
|
||||
|
||||
class MaemoToolChain : public ProjectExplorer::GccToolChain
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -1252,6 +1252,7 @@ void QtVersion::updateToolChainAndMkspec() const
|
||||
}
|
||||
} else if (qt_arch == "arm") {
|
||||
#ifdef QTCREATOR_WITH_MAEMO
|
||||
if (MaemoManager::instance()->isValidMaemoQtVersion(this))
|
||||
m_toolChains << ToolChainPtr(MaemoManager::instance()->maemoToolChain(this));
|
||||
#endif
|
||||
} else if (qmakeCXX == "cl" || qmakeCXX == "icl") {
|
||||
|
||||
Reference in New Issue
Block a user