OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / editmode.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "editmode.h"
34 #include "editormanager.h"
35 #include "coreconstants.h"
36 #include "modemanager.h"
37 #include "minisplitter.h"
38 #include "findplaceholder.h"
39 #include "outputpane.h"
40 #include "navigationwidget.h"
41 #include "rightpane.h"
42 #include "ieditor.h"
43 #include "ifile.h"
44
45 #include <QtCore/QLatin1String>
46 #include <QtGui/QHBoxLayout>
47 #include <QtGui/QWidget>
48 #include <QtGui/QSplitter>
49 #include <QtGui/QIcon>
50
51 using namespace Core;
52 using namespace Core::Internal;
53
54 EditMode::EditMode(EditorManager *editorManager) :
55     m_editorManager(editorManager),
56     m_splitter(new MiniSplitter),
57     m_rightSplitWidgetLayout(new QVBoxLayout)
58 {
59     setObjectName(QLatin1String("EditMode"));
60     m_rightSplitWidgetLayout->setSpacing(0);
61     m_rightSplitWidgetLayout->setMargin(0);
62     QWidget *rightSplitWidget = new QWidget;
63     rightSplitWidget->setLayout(m_rightSplitWidgetLayout);
64     m_rightSplitWidgetLayout->insertWidget(0, new Core::EditorManagerPlaceHolder(this));
65
66     MiniSplitter *rightPaneSplitter = new MiniSplitter;
67     rightPaneSplitter->insertWidget(0, rightSplitWidget);
68     rightPaneSplitter->insertWidget(1, new RightPanePlaceHolder(this));
69     rightPaneSplitter->setStretchFactor(0, 1);
70     rightPaneSplitter->setStretchFactor(1, 0);
71
72     MiniSplitter *splitter = new MiniSplitter;
73     splitter->setOrientation(Qt::Vertical);
74     splitter->insertWidget(0, rightPaneSplitter);
75     QWidget *outputPane = new Core::OutputPanePlaceHolder(this, splitter);
76     outputPane->setObjectName(QLatin1String("EditModeOutputPanePlaceHolder"));
77     splitter->insertWidget(1, outputPane);
78     splitter->setStretchFactor(0, 3);
79     splitter->setStretchFactor(1, 0);
80
81     m_splitter->insertWidget(0, new NavigationWidgetPlaceHolder(this));
82     m_splitter->insertWidget(1, splitter);
83     m_splitter->setStretchFactor(0, 0);
84     m_splitter->setStretchFactor(1, 1);
85
86     ModeManager *modeManager = ModeManager::instance();
87     connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
88             this, SLOT(grabEditorManager(Core::IMode*)));
89     m_splitter->setFocusProxy(m_editorManager);
90 }
91
92 EditMode::~EditMode()
93 {
94     // Make sure the editor manager does not get deleted
95     m_editorManager->setParent(0);
96     delete m_splitter;
97 }
98
99 QString EditMode::displayName() const
100 {
101     return tr("Edit");
102 }
103
104 QIcon EditMode::icon() const
105 {
106     return QIcon(QLatin1String(":/fancyactionbar/images/mode_Edit.png"));
107 }
108
109 int EditMode::priority() const
110 {
111     return Constants::P_MODE_EDIT;
112 }
113
114 QWidget* EditMode::widget()
115 {
116     return m_splitter;
117 }
118
119 QString EditMode::id() const
120 {
121     return QLatin1String(Constants::MODE_EDIT);
122 }
123
124 QString EditMode::type() const
125 {
126     return QLatin1String(Constants::MODE_EDIT_TYPE);
127 }
128
129 Context EditMode::context() const
130 {
131     static Context contexts(Constants::C_EDIT_MODE,
132                             Constants::C_EDITORMANAGER,
133                             Constants::C_NAVIGATION_PANE);
134     return contexts;
135 }
136
137 void EditMode::grabEditorManager(Core::IMode *mode)
138 {
139     if (mode != this)
140         return;
141
142     if (m_editorManager->currentEditor())
143         m_editorManager->currentEditor()->widget()->setFocus();
144 }