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.
17
#include "plasma_view_host.h"
21
#include <QtGui/QGraphicsProxyWidget>
22
#include <QtGui/QGraphicsLinearLayout>
23
#include <QtGui/QToolTip>
26
#include <KInputDialog>
27
#include <KMessageBox>
28
#include <Plasma/Applet>
29
#include <Plasma/ToolTipContent>
30
#include <Plasma/ToolTipManager>
32
#include <ggadget/file_manager_interface.h>
33
#include <ggadget/gadget_consts.h>
34
#include <ggadget/logger.h>
35
#include <ggadget/decorated_view_host.h>
36
#include <ggadget/options_interface.h>
37
#include <ggadget/script_context_interface.h>
38
#include <ggadget/script_runtime_interface.h>
39
#include <ggadget/script_runtime_manager.h>
40
#include <ggadget/qt/qt_graphics.h>
41
#include <ggadget/qt/utilities.h>
43
#include "plasma_view_host_internal.h"
46
using namespace ggadget::qt;
49
PlasmaViewHost::PlasmaViewHost(GadgetInfo *info, ViewHostInterface::Type type,
51
: d(new Private(info, type, popout)) {
54
PlasmaViewHost::~PlasmaViewHost() {
58
void PlasmaViewHost::Destroy() {
62
void PlasmaViewHost::SetView(ViewInterface *view) {
63
kDebug() << "PlasmaViewHost::SetView:" << this << "," << view;
67
void *PlasmaViewHost::GetNativeWidget() const {
71
void PlasmaViewHost::ViewCoordToNativeWidgetCoord(
72
double x, double y, double *widget_x, double *widget_y) const {
73
double zoom = d->view_->GetGraphics()->GetZoom();
74
if (widget_x) *widget_x = x * zoom;
75
if (widget_y) *widget_y = y * zoom;
78
void PlasmaViewHost::NativeWidgetCoordToViewCoord(
79
double x, double y, double *view_x, double *view_y) const {
80
double zoom = d->view_->GetGraphics()->GetZoom();
81
if (zoom == 0) return;
82
if (view_x) *view_x = x / zoom;
83
if (view_y) *view_y = y / zoom;
86
void PlasmaViewHost::QueueDraw() {
90
void PlasmaViewHost::QueueResize() {
94
void PlasmaViewHost::SetResizable(ViewInterface::ResizableMode mode) {
95
if (d->type_ != ViewHostInterface::VIEW_HOST_MAIN ||
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
static void UpdateTooltip(Plasma::Applet *applet, const QString &text) {
107
if (isHorizontal(applet->location())) {
108
Plasma::ToolTipContent data;
109
data.setMainText(text);
110
Plasma::ToolTipManager::self()->setContent(applet, data);
114
void PlasmaViewHost::SetCaption(const std::string &caption) {
115
d->caption_ = QString::fromUtf8(caption.c_str());
116
if (d->parent_widget_) {
117
d->parent_widget_->setWindowTitle(d->caption_);
119
UpdateTooltip(d->info->applet, d->caption_);
123
void PlasmaViewHost::SetCursor(ggadget::ViewInterface::CursorType type) {
124
Qt::CursorShape shape = ggadget::qt::GetQtCursorShape(type);
125
// Up to Qt4.4.3, There is a bug in handling cursor when
126
// QGraphicsProxyWidget is involved.
127
d->info->applet->setCursor(shape);
129
d->widget_->setCursor(shape);
132
void PlasmaViewHost::ShowTooltip(const std::string &tooltip) {
133
QToolTip::showText(QCursor::pos(), QString::fromUtf8(tooltip.c_str()));
136
void PlasmaViewHost::ShowTooltipAtPosition(const std::string &tooltip,
137
double x, double y) {
138
double widget_x = 0, widget_y = 0;
139
ViewCoordToNativeWidgetCoord(x, y, &widget_x, &widget_y);
140
QToolTip::showText(QPoint(widget_x, widget_y),
141
QString::fromUtf8(tooltip.c_str()));
144
bool PlasmaViewHost::ShowView(bool modal, int flags,
145
Slot1<bool, int> *feedback_handler) {
146
if (d->showView(modal, flags, feedback_handler)) {
147
if (d->parent_widget_) {
148
d->parent_widget_->setWindowTitle(d->caption_);
150
UpdateTooltip(d->info->applet, d->caption_);
157
void PlasmaViewHost::CloseView() {
161
bool PlasmaViewHost::ShowContextMenu(int button) {
162
return d->showContextMenu(button);
165
void PlasmaViewHost::Alert(const ViewInterface *view, const char *message) {
166
KMessageBox::information(NULL,message,
167
view->GetCaption().c_str());
170
ViewHostInterface::ConfirmResponse PlasmaViewHost::Confirm(
171
const ViewInterface *view, const char *message, bool) {
172
int ret = KMessageBox::questionYesNo(NULL,
174
view->GetCaption().c_str() );
175
return ret == KMessageBox::Yes ? CONFIRM_YES : CONFIRM_NO;
178
std::string PlasmaViewHost::Prompt(const ViewInterface *view,
180
const char *default_value) {
181
QString s = KInputDialog::getText(view->GetCaption().c_str(),
184
return s.toUtf8().data();
187
ViewHostInterface::Type PlasmaViewHost::GetType() const {
191
ViewInterface *PlasmaViewHost::GetView() const {
195
int PlasmaViewHost::GetDebugMode() const {
196
return d->info->view_debug_mode;
199
GadgetInfo *PlasmaViewHost::getInfo() {
203
} // namespace ggadget
204
#include "plasma_view_host_internal.moc"