Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
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 | #include <QLabel> |
49 | #include <QVBoxLayout> |
50 | #ifdef Q_WS_MAEMO_5 |
51 | # include <QScrollArea> |
52 | # include <QVBoxLayout> |
53 | # include "texteditautoresizer_maemo5.h" |
54 | #endif |
55 | |
56 | #include "loggerwidget.h" |
57 | |
58 | QT_BEGIN_NAMESPACE |
59 | |
60 | LoggerWidget::LoggerWidget(QWidget *parent) : |
61 | QMainWindow(parent), |
62 | m_visibilityOrigin(SettingsOrigin) |
63 | { |
64 | setAttribute(Qt::WA_QuitOnClose, false); |
65 | setWindowTitle(tr("Warnings")); |
66 | |
67 | m_plainTextEdit = new QPlainTextEdit(); |
68 | |
69 | #if defined(Q_OS_SYMBIAN) |
70 | QAction* clearAction = new QAction(tr("Clear"), this); |
71 | clearAction->setSoftKeyRole(QAction::PositiveSoftKey); |
72 | connect(clearAction, SIGNAL(triggered()), m_plainTextEdit, SLOT(clear())); |
73 | addAction(clearAction); |
74 | |
75 | m_plainTextEdit->setReadOnly(true); |
76 | QAction* backAction = new QAction( tr("Back"), this ); |
77 | backAction->setSoftKeyRole( QAction::NegativeSoftKey ); |
78 | connect(backAction, SIGNAL(triggered()), this, SLOT(hide())); |
79 | addAction( backAction ); |
80 | #endif |
81 | |
82 | #ifdef Q_WS_MAEMO_5 |
83 | new TextEditAutoResizer(m_plainTextEdit); |
84 | setAttribute(Qt::WA_Maemo5StackedWindow); |
85 | QScrollArea *area = new QScrollArea(); |
86 | area->setWidget(m_plainTextEdit); |
87 | area->setWidgetResizable(true); |
88 | setCentralWidget(area); |
89 | #else |
90 | setCentralWidget(m_plainTextEdit); |
91 | #endif |
92 | |
93 | m_noWarningsLabel = new QLabel(m_plainTextEdit); |
94 | m_noWarningsLabel->setText(tr("(No warnings)")); |
95 | m_noWarningsLabel->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); |
96 | QVBoxLayout *layout = new QVBoxLayout; |
97 | layout->addWidget(m_noWarningsLabel); |
98 | m_plainTextEdit->setLayout(layout); |
99 | connect(m_plainTextEdit, SIGNAL(textChanged()), this, SLOT(updateNoWarningsLabel())); |
100 | |
101 | readSettings(); |
102 | setupPreferencesMenu(); |
103 | } |
104 | |
105 | void LoggerWidget::append(const QString &msg) |
106 | { |
107 | m_plainTextEdit->appendPlainText(msg); |
108 | |
109 | if (!isVisible() && (defaultVisibility() == AutoShowWarnings)) |
110 | setVisible(true); |
111 | } |
112 | |
113 | LoggerWidget::Visibility LoggerWidget::defaultVisibility() const |
114 | { |
115 | return m_visibility; |
116 | } |
117 | |
118 | void LoggerWidget::setDefaultVisibility(LoggerWidget::Visibility visibility) |
119 | { |
120 | if (m_visibility == visibility) |
121 | return; |
122 | |
123 | m_visibility = visibility; |
124 | m_visibilityOrigin = CommandLineOrigin; |
125 | |
126 | m_preferencesMenu->setEnabled(m_visibilityOrigin == SettingsOrigin); |
127 | } |
128 | |
129 | QMenu *LoggerWidget::preferencesMenu() |
130 | { |
131 | return m_preferencesMenu; |
132 | } |
133 | |
134 | QAction *LoggerWidget::showAction() |
135 | { |
136 | return m_showWidgetAction; |
137 | } |
138 | |
139 | void LoggerWidget::readSettings() |
140 | { |
141 | QSettings settings; |
142 | QString warningsPreferences = settings.value(QLatin1String("warnings"), QLatin1String( "hide")).toString(); |
143 | if (warningsPreferences == QLatin1String("show")) { |
144 | m_visibility = ShowWarnings; |
145 | } else if (warningsPreferences == QLatin1String("hide")) { |
146 | m_visibility = HideWarnings; |
147 | } else { |
148 | m_visibility = AutoShowWarnings; |
149 | } |
150 | } |
151 | |
152 | void LoggerWidget::saveSettings() |
153 | { |
154 | if (m_visibilityOrigin != SettingsOrigin) |
155 | return; |
156 | |
157 | QString value = QLatin1String("autoShow"); |
158 | if (defaultVisibility() == ShowWarnings) { |
159 | value = QLatin1String("show"); |
160 | } else if (defaultVisibility() == HideWarnings) { |
161 | value = QLatin1String("hide"); |
162 | } |
163 | |
164 | QSettings settings; |
165 | settings.setValue(QLatin1String("warnings"), value); |
166 | } |
167 | |
168 | void LoggerWidget::warningsPreferenceChanged(QAction *action) |
169 | { |
170 | Visibility newSetting = static_cast<Visibility>(action->data().toInt()); |
171 | m_visibility = newSetting; |
172 | saveSettings(); |
173 | } |
174 | |
175 | void LoggerWidget::showEvent(QShowEvent *event) |
176 | { |
177 | QWidget::showEvent(event); |
178 | emit opened(); |
179 | } |
180 | |
181 | void LoggerWidget::closeEvent(QCloseEvent *event) |
182 | { |
183 | QWidget::closeEvent(event); |
184 | emit closed(); |
185 | } |
186 | |
187 | void LoggerWidget::setupPreferencesMenu() |
188 | { |
189 | m_preferencesMenu = new QMenu(tr("Warnings")); |
190 | QActionGroup *warnings = new QActionGroup(m_preferencesMenu); |
191 | warnings->setExclusive(true); |
192 | |
193 | connect(warnings, SIGNAL(triggered(QAction*)), this, SLOT(warningsPreferenceChanged(QAction*))); |
194 | |
195 | QAction *showWarningsPreference = new QAction(tr("Show by default"), m_preferencesMenu); |
196 | showWarningsPreference->setCheckable(true); |
197 | showWarningsPreference->setData(LoggerWidget::ShowWarnings); |
198 | warnings->addAction(showWarningsPreference); |
199 | m_preferencesMenu->addAction(showWarningsPreference); |
200 | |
201 | QAction *hideWarningsPreference = new QAction(tr("Hide by default"), m_preferencesMenu); |
202 | hideWarningsPreference->setCheckable(true); |
203 | hideWarningsPreference->setData(LoggerWidget::HideWarnings); |
204 | warnings->addAction(hideWarningsPreference); |
205 | m_preferencesMenu->addAction(hideWarningsPreference); |
206 | |
207 | QAction *autoWarningsPreference = new QAction(tr("Show for first warning"), m_preferencesMenu); |
208 | autoWarningsPreference->setCheckable(true); |
209 | autoWarningsPreference->setData(LoggerWidget::AutoShowWarnings); |
210 | warnings->addAction(autoWarningsPreference); |
211 | m_preferencesMenu->addAction(autoWarningsPreference); |
212 | |
213 | switch (defaultVisibility()) { |
214 | case LoggerWidget::ShowWarnings: |
215 | showWarningsPreference->setChecked(true); |
216 | break; |
217 | case LoggerWidget::HideWarnings: |
218 | hideWarningsPreference->setChecked(true); |
219 | break; |
220 | default: |
221 | autoWarningsPreference->setChecked(true); |
222 | } |
223 | } |
224 | |
225 | void LoggerWidget::updateNoWarningsLabel() |
226 | { |
227 | m_noWarningsLabel->setVisible(m_plainTextEdit->toPlainText().length() == 0); |
228 | } |
229 | |
230 | QT_END_NAMESPACE |
231 |
Warning: That file was not part of the compilation database. It may have many parsing errors.