OSDN Git Service

bf1b15bb7c0f5c0a22a91bee89bab93d3e81b26d
[qt-creator-jp/qt-creator-jp.git] / doc / pluginhowto / examples / loggermode / loggermode.cpp
1 /***************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the documentation of Qt Creator.
8 **
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ****************************************************************************/
38
39 #include "loggermode.h"
40 #include "loggermodewidget.h"
41
42 #include <extensionsystem/pluginmanager.h>
43 #include <coreplugin/icore.h>
44 #include <coreplugin/coreconstants.h>
45 #include <utils/styledbar.h>
46 #include <utils/iwelcomepage.h>
47 #include <coreplugin/uniqueidmanager.h>
48 #include <extensionsystem/pluginmanager.h>
49 #include <projectexplorer/projectexplorer.h>
50 #include <projectexplorer/session.h>
51 #include <projectexplorer/project.h>
52
53 #include <QtCore/QSettings>
54
55 #include <QStackedWidget>
56 #include <QLabel>
57 #include <QComboBox>
58 #include <QVBoxLayout>
59 #include <QPushbutton>
60 #include <QMessageBox>
61
62
63
64 struct LoggerModeData
65 {
66    QWidget *m_widget;
67    QLabel *currentProjectsLabel;
68    QLabel *addProjectLabel;
69    QComboBox *currentProjectsCombobox;
70    QComboBox *addProjectComboBox;
71    QPushButton *addToProjectButton;
72    QStackedWidget *stackedWidget;
73 };
74
75 LoggerMode::LoggerMode()
76 {
77     d = new LoggerModeData;
78     d->m_widget = new QWidget;
79
80     d->currentProjectsLabel = new QLabel("Current projects :");
81     d->currentProjectsLabel->setFixedWidth(90);
82     d->currentProjectsCombobox = new QComboBox;
83     d->currentProjectsCombobox->setSizePolicy(QSizePolicy::Preferred,
84                                               QSizePolicy::Preferred);
85
86     d->addProjectLabel = new QLabel("Add Project :");
87     d->addProjectLabel->setAlignment(Qt::AlignRight);
88     d->addProjectComboBox = new QComboBox;
89     d->addProjectComboBox->setSizePolicy(QSizePolicy::Preferred,
90                                          QSizePolicy::Preferred);
91     d->addProjectComboBox->setEditable(true);
92
93     d->addToProjectButton = new QPushButton(tr("Add Project"));
94     d->addToProjectButton->setFixedWidth(80);
95
96
97     QHBoxLayout *hLayout = new QHBoxLayout;
98     hLayout->addWidget(d->currentProjectsLabel);
99     hLayout->addWidget(d->currentProjectsCombobox);
100     hLayout->addWidget(d->addProjectLabel);
101     hLayout->addWidget(d->addProjectComboBox);
102     hLayout->addWidget(d->addToProjectButton);
103
104
105
106     d->stackedWidget = new QStackedWidget;
107
108     QVBoxLayout* layout = new QVBoxLayout;
109     layout->addLayout(hLayout);
110     layout->addWidget(d->stackedWidget);
111
112     d->m_widget->setLayout(layout);
113
114     d->addProjectComboBox->addItem("Project 1");
115     d->addProjectComboBox->addItem("Project 2");
116     d->addProjectComboBox->addItem("Project 3");
117
118     connect(d->addToProjectButton,SIGNAL(clicked()),
119             this,SLOT(addItem()));
120
121     connect(d->currentProjectsCombobox, SIGNAL(currentIndexChanged(int)),
122             d->stackedWidget, SLOT(setCurrentIndex(int)));
123 }
124
125
126 LoggerMode::~LoggerMode()
127 {
128     delete d->m_widget;
129     delete d;
130 }
131
132 void LoggerMode::addItem()
133 {
134     d->currentProjectsCombobox->addItem(d->addProjectComboBox->currentText());
135     addNewStackWidgetPage(d->currentProjectsCombobox->itemText(0));
136     d->addProjectComboBox->removeItem(d->addProjectComboBox->currentIndex());
137 }
138
139 QString LoggerMode::name() const
140 {
141     return tr("LoggerMode");
142 }
143
144
145 QIcon LoggerMode::icon() const
146 {
147     return QIcon(QLatin1String(":/core/images/qtcreator_logo_32.png"));
148 }
149
150
151 int LoggerMode::priority() const
152 {
153     return 0;
154 }
155
156
157 QWidget* LoggerMode::widget()
158 {
159     return d->m_widget;
160 }
161
162
163 const char* LoggerMode::uniqueModeName() const
164 {
165     return "LoggerMode" ;
166 }
167
168 QList<int> LoggerMode::context() const
169 {
170      return QList<int>();
171 }
172
173 void LoggerMode::addNewStackWidgetPage(const QString projectName)
174 {
175     d->stackedWidget->addWidget(new LoggerModeWidget(projectName));
176 }
177