forked from qt-creator/qt-creator
Utils: Introduce HostOsInfo class.
The class' member functions are intended to be used instead of the Q_OS_* macros in all contexts where the latter are not syntactically required. This lowers the likelihood of changes made on one platform breaking the build on another, e.g. due to the code model missing symbols in #ifdef'ed out code when refactoring. Change-Id: I4a54788591b4c8f8d589b8368a6c683d4155c9fa Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include "icontext.h"
|
||||
#include "id.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
|
||||
@@ -438,9 +440,8 @@ static QString msgActionWarning(QAction *newAction, int k, QAction *oldAction)
|
||||
|
||||
void Action::addOverrideAction(QAction *action, const Core::Context &context, bool scriptable)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
action->setIconVisibleInMenu(false);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
action->setIconVisibleInMenu(false);
|
||||
if (isEmpty())
|
||||
m_action->initialize(action);
|
||||
if (context.isEmpty()) {
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "icore.h"
|
||||
#include "id.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/treewidgetcolumnstretcher.h>
|
||||
|
||||
#include <QKeyEvent>
|
||||
@@ -166,18 +167,18 @@ bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
|
||||
int columnCount = item->columnCount();
|
||||
for (int i = 0; !visible && i < columnCount; ++i) {
|
||||
QString text = item->text(i);
|
||||
#ifdef Q_OS_MAC
|
||||
// accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
|
||||
if (i == columnCount - 1) {
|
||||
QKeySequence key = QKeySequence::fromString(text, QKeySequence::NativeText);
|
||||
if (!key.isEmpty()) {
|
||||
text = key.toString(QKeySequence::PortableText);
|
||||
text.replace(QLatin1String("Ctrl"), QLatin1String("Cmd"));
|
||||
text.replace(QLatin1String("Meta"), QLatin1String("Ctrl"));
|
||||
text.replace(QLatin1String("Alt"), QLatin1String("Opt"));
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
// accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
|
||||
if (i == columnCount - 1) {
|
||||
QKeySequence key = QKeySequence::fromString(text, QKeySequence::NativeText);
|
||||
if (!key.isEmpty()) {
|
||||
text = key.toString(QKeySequence::PortableText);
|
||||
text.replace(QLatin1String("Ctrl"), QLatin1String("Cmd"));
|
||||
text.replace(QLatin1String("Meta"), QLatin1String("Ctrl"));
|
||||
text.replace(QLatin1String("Alt"), QLatin1String("Opt"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
visible |= (bool)text.contains(filterString, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@@ -604,15 +605,15 @@ void BaseFileWizard::setupWizard(QWizard *w)
|
||||
w->setOption(QWizard::NoBackButtonOnStartPage, true);
|
||||
w->setWindowFlags(w->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
w->setButtonLayout(QList<QWizard::WizardButton>()
|
||||
<< QWizard::CancelButton
|
||||
<< QWizard::Stretch
|
||||
<< QWizard::BackButton
|
||||
<< QWizard::NextButton
|
||||
<< QWizard::CommitButton
|
||||
<< QWizard::FinishButton);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
w->setButtonLayout(QList<QWizard::WizardButton>()
|
||||
<< QWizard::CancelButton
|
||||
<< QWizard::Stretch
|
||||
<< QWizard::BackButton
|
||||
<< QWizard::NextButton
|
||||
<< QWizard::CommitButton
|
||||
<< QWizard::FinishButton);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "externaltoolconfig.h"
|
||||
#include "ui_externaltoolconfig.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -351,13 +352,13 @@ QModelIndex ExternalToolModel::addTool(const QModelIndex &atIndex)
|
||||
tool->setDescription(tr("This tool prints a line of useful text"));
|
||||
//: Sample external tool text
|
||||
const QString text = tr("Useful text");
|
||||
#ifdef Q_OS_WIN
|
||||
tool->setExecutables(QStringList(QLatin1String("cmd")));
|
||||
tool->setArguments(QLatin1String("/c echo ") + text);
|
||||
#else
|
||||
tool->setExecutables(QStringList(QLatin1String("echo")));
|
||||
tool->setArguments(text);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isWindowsHost()) {
|
||||
tool->setExecutables(QStringList(QLatin1String("cmd")));
|
||||
tool->setArguments(QLatin1String("/c echo ") + text);
|
||||
} else {
|
||||
tool->setExecutables(QStringList(QLatin1String("echo")));
|
||||
tool->setArguments(text);
|
||||
}
|
||||
|
||||
int pos;
|
||||
QModelIndex parent;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@@ -54,12 +55,10 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
#ifdef Q_OS_MAC
|
||||
|
||||
// QDialogButtonBox's behavior for "destructive" is wrong, the "do not save" should be left-aligned
|
||||
QDialogButtonBox::ButtonRole discardButtonRole = QDialogButtonBox::ResetRole;
|
||||
#else
|
||||
QDialogButtonBox::ButtonRole discardButtonRole = QDialogButtonBox::DestructiveRole;
|
||||
#endif
|
||||
const QDialogButtonBox::ButtonRole discardButtonRole = Utils::HostOsInfo::isMacHost()
|
||||
? QDialogButtonBox::ResetRole : QDialogButtonBox::DestructiveRole;
|
||||
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Do not Save"), discardButtonRole);
|
||||
m_ui.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
|
||||
m_ui.treeWidget->setFocus();
|
||||
@@ -86,9 +85,8 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
||||
|
||||
m_ui.treeWidget->resizeColumnToContents(0);
|
||||
m_ui.treeWidget->selectAll();
|
||||
#ifdef Q_OS_MAC
|
||||
m_ui.treeWidget->setAlternatingRowColors(true);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
m_ui.treeWidget->setAlternatingRowColors(true);
|
||||
adjustButtonWidths();
|
||||
updateSaveButton();
|
||||
|
||||
@@ -135,13 +133,13 @@ void SaveItemsDialog::adjustButtonWidths()
|
||||
if (hint > maxTextWidth)
|
||||
maxTextWidth = hint;
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
QPushButton *cancelButton = m_ui.buttonBox->button(QDialogButtonBox::Cancel);
|
||||
int cancelButtonWidth = cancelButton->sizeHint().width();
|
||||
if (cancelButtonWidth > maxTextWidth)
|
||||
maxTextWidth = cancelButtonWidth;
|
||||
cancelButton->setMinimumWidth(maxTextWidth);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
QPushButton *cancelButton = m_ui.buttonBox->button(QDialogButtonBox::Cancel);
|
||||
int cancelButtonWidth = cancelButton->sizeHint().width();
|
||||
if (cancelButtonWidth > maxTextWidth)
|
||||
maxTextWidth = cancelButtonWidth;
|
||||
cancelButton->setMinimumWidth(maxTextWidth);
|
||||
}
|
||||
saveButton->setMinimumWidth(maxTextWidth);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include "icore.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/filterlineedit.h>
|
||||
|
||||
#include <QSettings>
|
||||
@@ -295,11 +296,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
|
||||
createGui();
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
#ifdef Q_OS_MAC
|
||||
setWindowTitle(tr("Preferences"));
|
||||
#else
|
||||
setWindowTitle(tr("Options"));
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
setWindowTitle(tr("Preferences"));
|
||||
else
|
||||
setWindowTitle(tr("Options"));
|
||||
|
||||
m_model->setPages(m_pages,
|
||||
ExtensionSystem::PluginManager::getObjects<IOptionsPageProvider>());
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "vcsmanager.h"
|
||||
#include "coreconstants.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/reloadpromptutils.h>
|
||||
@@ -178,17 +179,17 @@ QFileSystemWatcher *DocumentManagerPrivate::fileWatcher()
|
||||
|
||||
QFileSystemWatcher *DocumentManagerPrivate::linkWatcher()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
if (!m_linkWatcher) {
|
||||
m_linkWatcher = new QFileSystemWatcher(m_instance);
|
||||
m_linkWatcher->setObjectName(QLatin1String("_qt_autotest_force_engine_poller"));
|
||||
QObject::connect(m_linkWatcher, SIGNAL(fileChanged(QString)),
|
||||
m_instance, SLOT(changedFile(QString)));
|
||||
if (Utils::HostOsInfo::isAnyUnixHost()) {
|
||||
if (!m_linkWatcher) {
|
||||
m_linkWatcher = new QFileSystemWatcher(m_instance);
|
||||
m_linkWatcher->setObjectName(QLatin1String("_qt_autotest_force_engine_poller"));
|
||||
QObject::connect(m_linkWatcher, SIGNAL(fileChanged(QString)),
|
||||
m_instance, SLOT(changedFile(QString)));
|
||||
}
|
||||
return m_linkWatcher;
|
||||
}
|
||||
return m_linkWatcher;
|
||||
#else
|
||||
|
||||
return fileWatcher();
|
||||
#endif
|
||||
}
|
||||
|
||||
DocumentManagerPrivate::DocumentManagerPrivate(QMainWindow *mw) :
|
||||
@@ -197,11 +198,7 @@ DocumentManagerPrivate::DocumentManagerPrivate(QMainWindow *mw) :
|
||||
m_linkWatcher(0),
|
||||
m_blockActivated(false),
|
||||
m_lastVisitedDirectory(QDir::currentPath()),
|
||||
#ifdef Q_OS_MAC // Creator is in bizarre places when launched via finder.
|
||||
m_useProjectsDirectory(true),
|
||||
#else
|
||||
m_useProjectsDirectory(false),
|
||||
#endif
|
||||
m_useProjectsDirectory(Utils::HostOsInfo::isMacHost()), // Creator is in bizarre places when launched via finder.
|
||||
m_blockedIDocument(0)
|
||||
{
|
||||
}
|
||||
@@ -489,9 +486,8 @@ QString DocumentManager::fixFileName(const QString &fileName, FixMode fixmode)
|
||||
s = QDir::cleanPath(s);
|
||||
}
|
||||
s = QDir::toNativeSeparators(s);
|
||||
#ifdef Q_OS_WIN
|
||||
s = s.toLower();
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isWindowsHost())
|
||||
s = s.toLower();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDateTime>
|
||||
@@ -1700,9 +1701,8 @@ void EditorManager::updateActions()
|
||||
fName = curEditor->displayName();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
window()->setWindowModified(curEditor->document()->isModified());
|
||||
#endif
|
||||
if (HostOsInfo::isMacHost())
|
||||
window()->setWindowModified(curEditor->document()->isModified());
|
||||
bool ww = curEditor->document()->isModified() && curEditor->document()->isFileReadOnly();
|
||||
if (ww != curEditor->document()->hasWriteWarning()) {
|
||||
curEditor->document()->setWriteWarning(ww);
|
||||
@@ -1739,10 +1739,8 @@ void EditorManager::updateActions()
|
||||
curEditor->document()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable"));
|
||||
}
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
} else { // curEditor
|
||||
} else /* curEditor */ if (HostOsInfo::isMacHost()) {
|
||||
window()->setWindowModified(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
setCloseSplitEnabled(d->m_splitter, d->m_splitter->isSplitter());
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "editorview.h"
|
||||
#include "idocument.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFocusEvent>
|
||||
@@ -61,16 +62,14 @@ OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) :
|
||||
m_editorList->setIndentation(0);
|
||||
m_editorList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_editorList->setTextElideMode(Qt::ElideMiddle);
|
||||
#ifdef Q_OS_MAC
|
||||
m_editorList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
m_editorList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
m_editorList->installEventFilter(this);
|
||||
|
||||
// We disable the frame on this list view and use a QFrame around it instead.
|
||||
// This improves the look with QGTKStyle.
|
||||
#ifndef Q_OS_MAC
|
||||
setFrameStyle(m_editorList->frameStyle());
|
||||
#endif
|
||||
if (!Utils::HostOsInfo::isMacHost())
|
||||
setFrameStyle(m_editorList->frameStyle());
|
||||
m_editorList->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/parameteraction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/styledbar.h>
|
||||
@@ -152,10 +153,10 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
|
||||
d->m_forwardButton= new QToolButton(this);
|
||||
d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
d->m_horizontalSplitAction->setIconVisibleInMenu(false);
|
||||
d->m_verticalSplitAction->setIconVisibleInMenu(false);
|
||||
#endif
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
d->m_horizontalSplitAction->setIconVisibleInMenu(false);
|
||||
d->m_verticalSplitAction->setIconVisibleInMenu(false);
|
||||
}
|
||||
|
||||
d->m_splitButton->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
|
||||
d->m_splitButton->setToolTip(tr("Split"));
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "fancytabwidget.h"
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/styledbar.h>
|
||||
|
||||
@@ -289,8 +290,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
} else {
|
||||
painter->setPen(selected ? Utils::StyleHelper::panelTextColor() : QColor(255, 255, 255, 120));
|
||||
}
|
||||
#ifndef Q_OS_MAC
|
||||
if (!selected && enabled) {
|
||||
if (!Utils::HostOsInfo::isMacHost() && !selected && enabled) {
|
||||
painter->save();
|
||||
int fader = int(m_tabs[tabIndex]->fader());
|
||||
QLinearGradient grad(rect.topLeft(), rect.topRight());
|
||||
@@ -303,7 +303,6 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
|
||||
painter->restore();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!enabled)
|
||||
painter->setOpacity(0.7);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "fileiconprovider.h"
|
||||
#include "mimedatabase.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QApplication>
|
||||
@@ -44,6 +45,8 @@
|
||||
#include <QIcon>
|
||||
#include <QStyle>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
/*!
|
||||
\class Core::FileIconProvider
|
||||
|
||||
@@ -139,14 +142,13 @@ QIcon FileIconProvider::icon(const QFileInfo &fileInfo) const
|
||||
}
|
||||
}
|
||||
// Get icon from OS.
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
|
||||
return QFileIconProvider::icon(fileInfo);
|
||||
#else
|
||||
if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost())
|
||||
return QFileIconProvider::icon(fileInfo);
|
||||
|
||||
// File icons are unknown on linux systems.
|
||||
return (fileInfo.isDir()) ?
|
||||
QFileIconProvider::icon(fileInfo) :
|
||||
d->m_unknownFileIcon;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/styledbar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -198,11 +199,7 @@ QWidget *OutputPaneManager::buttonsWidget()
|
||||
// Return shortcut as Ctrl+<number>
|
||||
static inline int paneShortCut(int number)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
int modifier = Qt::CTRL;
|
||||
#else
|
||||
int modifier = Qt::ALT;
|
||||
#endif
|
||||
const int modifier = Utils::HostOsInfo::isMacHost() ? Qt::CTRL : Qt::ALT;
|
||||
return modifier | (Qt::Key_0 + number);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user