[844] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
| 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include <qglobal.h>
|
---|
| 43 | #include <QDebug>
|
---|
| 44 | #include <QSettings>
|
---|
| 45 | #include <QActionGroup>
|
---|
| 46 | #include <QMenu>
|
---|
| 47 | #include <QPlainTextEdit>
|
---|
| 48 | #ifdef Q_WS_MAEMO_5
|
---|
| 49 | # include <QScrollArea>
|
---|
| 50 | # include <QVBoxLayout>
|
---|
| 51 | # include "texteditautoresizer_maemo5.h"
|
---|
| 52 | #endif
|
---|
| 53 |
|
---|
| 54 | #include "loggerwidget.h"
|
---|
| 55 |
|
---|
| 56 | QT_BEGIN_NAMESPACE
|
---|
| 57 |
|
---|
| 58 | LoggerWidget::LoggerWidget(QWidget *parent) :
|
---|
| 59 | QMainWindow(parent),
|
---|
| 60 | m_visibilityOrigin(SettingsOrigin)
|
---|
| 61 | {
|
---|
| 62 | setAttribute(Qt::WA_QuitOnClose, false);
|
---|
| 63 | setWindowTitle(tr("Warnings"));
|
---|
| 64 |
|
---|
| 65 | m_plainTextEdit = new QPlainTextEdit();
|
---|
| 66 |
|
---|
| 67 | #ifdef Q_WS_MAEMO_5
|
---|
| 68 | new TextEditAutoResizer(m_plainTextEdit);
|
---|
| 69 | setAttribute(Qt::WA_Maemo5StackedWindow);
|
---|
| 70 | QScrollArea *area = new QScrollArea();
|
---|
| 71 | area->setWidget(m_plainTextEdit);
|
---|
| 72 | area->setWidgetResizable(true);
|
---|
| 73 | setCentralWidget(area);
|
---|
| 74 | #else
|
---|
| 75 | setCentralWidget(m_plainTextEdit);
|
---|
| 76 | #endif
|
---|
| 77 | readSettings();
|
---|
| 78 | setupPreferencesMenu();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void LoggerWidget::append(const QString &msg)
|
---|
| 82 | {
|
---|
| 83 | m_plainTextEdit->appendPlainText(msg);
|
---|
| 84 |
|
---|
| 85 | if (!isVisible() && (defaultVisibility() == AutoShowWarnings))
|
---|
| 86 | setVisible(true);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | LoggerWidget::Visibility LoggerWidget::defaultVisibility() const
|
---|
| 90 | {
|
---|
| 91 | return m_visibility;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | void LoggerWidget::setDefaultVisibility(LoggerWidget::Visibility visibility)
|
---|
| 95 | {
|
---|
| 96 | if (m_visibility == visibility)
|
---|
| 97 | return;
|
---|
| 98 |
|
---|
| 99 | m_visibility = visibility;
|
---|
| 100 | m_visibilityOrigin = CommandLineOrigin;
|
---|
| 101 |
|
---|
| 102 | m_preferencesMenu->setEnabled(m_visibilityOrigin == SettingsOrigin);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | QMenu *LoggerWidget::preferencesMenu()
|
---|
| 106 | {
|
---|
| 107 | return m_preferencesMenu;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | QAction *LoggerWidget::showAction()
|
---|
| 111 | {
|
---|
| 112 | return m_showWidgetAction;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void LoggerWidget::readSettings()
|
---|
| 116 | {
|
---|
| 117 | QSettings settings;
|
---|
| 118 | QString warningsPreferences = settings.value("warnings", "hide").toString();
|
---|
| 119 | if (warningsPreferences == "show") {
|
---|
| 120 | m_visibility = ShowWarnings;
|
---|
| 121 | } else if (warningsPreferences == "hide") {
|
---|
| 122 | m_visibility = HideWarnings;
|
---|
| 123 | } else {
|
---|
| 124 | m_visibility = AutoShowWarnings;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | void LoggerWidget::saveSettings()
|
---|
| 129 | {
|
---|
| 130 | if (m_visibilityOrigin != SettingsOrigin)
|
---|
| 131 | return;
|
---|
| 132 |
|
---|
| 133 | QString value = "autoShow";
|
---|
| 134 | if (defaultVisibility() == ShowWarnings) {
|
---|
| 135 | value = "show";
|
---|
| 136 | } else if (defaultVisibility() == HideWarnings) {
|
---|
| 137 | value = "hide";
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | QSettings settings;
|
---|
| 141 | settings.setValue("warnings", value);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | void LoggerWidget::warningsPreferenceChanged(QAction *action)
|
---|
| 145 | {
|
---|
| 146 | Visibility newSetting = static_cast<Visibility>(action->data().toInt());
|
---|
| 147 | m_visibility = newSetting;
|
---|
| 148 | saveSettings();
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | void LoggerWidget::showEvent(QShowEvent *event)
|
---|
| 152 | {
|
---|
| 153 | QWidget::showEvent(event);
|
---|
| 154 | emit opened();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void LoggerWidget::closeEvent(QCloseEvent *event)
|
---|
| 158 | {
|
---|
| 159 | QWidget::closeEvent(event);
|
---|
| 160 | emit closed();
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void LoggerWidget::setupPreferencesMenu()
|
---|
| 164 | {
|
---|
| 165 | m_preferencesMenu = new QMenu(tr("Warnings"));
|
---|
| 166 | QActionGroup *warnings = new QActionGroup(m_preferencesMenu);
|
---|
| 167 | warnings->setExclusive(true);
|
---|
| 168 |
|
---|
| 169 | connect(warnings, SIGNAL(triggered(QAction*)), this, SLOT(warningsPreferenceChanged(QAction*)));
|
---|
| 170 |
|
---|
| 171 | QAction *showWarningsPreference = new QAction(tr("Show by default"), m_preferencesMenu);
|
---|
| 172 | showWarningsPreference->setCheckable(true);
|
---|
| 173 | showWarningsPreference->setData(LoggerWidget::ShowWarnings);
|
---|
| 174 | warnings->addAction(showWarningsPreference);
|
---|
| 175 | m_preferencesMenu->addAction(showWarningsPreference);
|
---|
| 176 |
|
---|
| 177 | QAction *hideWarningsPreference = new QAction(tr("Hide by default"), m_preferencesMenu);
|
---|
| 178 | hideWarningsPreference->setCheckable(true);
|
---|
| 179 | hideWarningsPreference->setData(LoggerWidget::HideWarnings);
|
---|
| 180 | warnings->addAction(hideWarningsPreference);
|
---|
| 181 | m_preferencesMenu->addAction(hideWarningsPreference);
|
---|
| 182 |
|
---|
| 183 | QAction *autoWarningsPreference = new QAction(tr("Show for first warning"), m_preferencesMenu);
|
---|
| 184 | autoWarningsPreference->setCheckable(true);
|
---|
| 185 | autoWarningsPreference->setData(LoggerWidget::AutoShowWarnings);
|
---|
| 186 | warnings->addAction(autoWarningsPreference);
|
---|
| 187 | m_preferencesMenu->addAction(autoWarningsPreference);
|
---|
| 188 |
|
---|
| 189 | switch (defaultVisibility()) {
|
---|
| 190 | case LoggerWidget::ShowWarnings:
|
---|
| 191 | showWarningsPreference->setChecked(true);
|
---|
| 192 | break;
|
---|
| 193 | case LoggerWidget::HideWarnings:
|
---|
| 194 | hideWarningsPreference->setChecked(true);
|
---|
| 195 | break;
|
---|
| 196 | default:
|
---|
| 197 | autoWarningsPreference->setChecked(true);
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | QT_END_NAMESPACE
|
---|