2 Copyright 2007 Google Inc.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 #include <KMessageBox>
20 #include <QtGui/QGraphicsProxyWidget>
21 #include <QtGui/QGraphicsLinearLayout>
22 #include <QtGui/QToolTip>
24 #include <KInputDialog>
25 #include <ggadget/file_manager_interface.h>
26 #include <ggadget/gadget_consts.h>
27 #include <ggadget/logger.h>
28 #include <ggadget/decorated_view_host.h>
29 #include <ggadget/options_interface.h>
30 #include <ggadget/script_context_interface.h>
31 #include <ggadget/script_runtime_interface.h>
32 #include <ggadget/script_runtime_manager.h>
33 #include <ggadget/qt/qt_graphics.h>
34 #include <ggadget/qt/utilities.h>
35 #include "plasma_view_host.h"
36 #include "plasma_view_host_internal.h"
38 #include <Plasma/Applet>
40 using namespace ggadget::qt
;
43 PlasmaViewHost::PlasmaViewHost(GadgetInfo
*info
, ViewHostInterface::Type type
,
45 : d(new Private(info
, type
, popout
)) {
48 PlasmaViewHost::~PlasmaViewHost() {
52 void PlasmaViewHost::Destroy() {
56 void PlasmaViewHost::SetView(ViewInterface
*view
) {
57 kDebug() << "PlasmaViewHost::SetView:" << this << "," << view
;
58 if (d
->view_
== view
) return;
63 void *PlasmaViewHost::GetNativeWidget() const {
67 void PlasmaViewHost::ViewCoordToNativeWidgetCoord(
68 double x
, double y
, double *widget_x
, double *widget_y
) const {
69 double zoom
= d
->view_
->GetGraphics()->GetZoom();
76 void PlasmaViewHost::NativeWidgetCoordToViewCoord(
77 double x
, double y
, double *view_x
, double *view_y
) const {
78 double zoom
= d
->view_
->GetGraphics()->GetZoom();
79 if (zoom
== 0) return;
80 if (view_x
) *view_x
= x
/ zoom
;
81 if (view_y
) *view_y
= y
/ zoom
;
84 void PlasmaViewHost::QueueDraw() {
88 void PlasmaViewHost::QueueResize() {
92 void PlasmaViewHost::EnableInputShapeMask(bool enable
) {
95 void PlasmaViewHost::SetResizable(ViewInterface::ResizableMode mode
) {
96 if (d
->type_
!= ViewHostInterface::VIEW_HOST_MAIN
|| d
->is_popout_
||
99 if (mode
== ViewInterface::RESIZABLE_TRUE
)
100 d
->info
->applet
->setAspectRatioMode(Plasma::IgnoreAspectRatio
);
102 d
->info
->applet
->setAspectRatioMode(Plasma::KeepAspectRatio
);
103 kDebug() << "SetResizable:" << mode
<< d
->info
->applet
->aspectRatioMode();
106 void PlasmaViewHost::SetCaption(const std::string
&caption
) {
107 d
->caption_
= QString::fromUtf8(caption
.c_str());
108 if (d
->parent_widget_
)
109 d
->parent_widget_
->setWindowTitle(d
->caption_
);
112 void PlasmaViewHost::SetShowCaptionAlways(bool always
) {
116 void PlasmaViewHost::SetCursor(ggadget::ViewInterface::CursorType type
) {
117 Qt::CursorShape shape
= ggadget::qt::GetQtCursorShape(type
);
118 // Up to Qt4.4.3, There is a bug in handling cursor when
119 // QGraphicsProxyWidget is involved.
120 d
->info
->applet
->setCursor(shape
);
122 d
->widget_
->setCursor(shape
);
125 void PlasmaViewHost::ShowTooltip(const std::string
&tooltip
) {
126 QToolTip::showText(QCursor::pos(), QString::fromUtf8(tooltip
.c_str()));
129 void PlasmaViewHost::ShowTooltipAtPosition(const std::string
&tooltip
,
130 double x
, double y
) {
134 bool PlasmaViewHost::ShowView(bool modal
, int flags
,
135 Slot1
<bool, int> *feedback_handler
) {
136 if (d
->showView(modal
, flags
, feedback_handler
)) {
137 if (d
->parent_widget_
)
138 d
->parent_widget_
->setWindowTitle(d
->caption_
);
144 void PlasmaViewHost::CloseView() {
148 bool PlasmaViewHost::ShowContextMenu(int button
) {
149 return d
->showContextMenu(button
);
152 void PlasmaViewHost::Alert(const ViewInterface
*view
, const char *message
) {
153 KMessageBox::information(NULL
,message
,
154 view
->GetCaption().c_str());
157 ViewHostInterface::ConfirmResponse
PlasmaViewHost::Confirm(
158 const ViewInterface
*view
, const char *message
, bool) {
159 int ret
= KMessageBox::questionYesNo(NULL
,
161 view
->GetCaption().c_str() );
162 if (ret
== KMessageBox::Yes
)
168 std::string
PlasmaViewHost::Prompt(const ViewInterface
*view
,
170 const char *default_value
) {
171 QString s
= KInputDialog::getText(view
->GetCaption().c_str(),
173 return s
.toUtf8().data();
176 ViewHostInterface::Type
PlasmaViewHost::GetType() const {
180 ViewInterface
*PlasmaViewHost::GetView() const {
184 int PlasmaViewHost::GetDebugMode() const {
185 return d
->info
->view_debug_mode
;
188 GadgetInfo
*PlasmaViewHost::getInfo() {
192 } // namespace ggadget
193 #include "plasma_view_host_internal.moc"