• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

plasma_view_host.cpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2007 Google Inc.
00003 
00004   Licensed under the Apache License, Version 2.0 (the "License");
00005   you may not use this file except in compliance with the License.
00006   You may obtain a copy of the License at
00007 
00008        http://www.apache.org/licenses/LICENSE-2.0
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 */
00016 
00017 #include <sys/time.h>
00018 
00019 #include <KMessageBox>
00020 #include <QtGui/QGraphicsProxyWidget>
00021 #include <QtGui/QGraphicsLinearLayout>
00022 #include <QtGui/QToolTip>
00023 
00024 #include <KInputDialog>
00025 #include <ggadget/file_manager_interface.h>
00026 #include <ggadget/gadget_consts.h>
00027 #include <ggadget/logger.h>
00028 #include <ggadget/decorated_view_host.h>
00029 #include <ggadget/options_interface.h>
00030 #include <ggadget/script_context_interface.h>
00031 #include <ggadget/script_runtime_interface.h>
00032 #include <ggadget/script_runtime_manager.h>
00033 #include <ggadget/qt/qt_graphics.h>
00034 #include <ggadget/qt/utilities.h>
00035 #include "plasma_view_host.h"
00036 #include "plasma_view_host_internal.h"
00037 
00038 #include <Plasma/Applet>
00039 
00040 using namespace ggadget::qt;
00041 namespace ggadget {
00042 
00043 PlasmaViewHost::PlasmaViewHost(GadgetInfo *info, ViewHostInterface::Type type,
00044                                bool popout)
00045   : d(new Private(info, type, popout)) {
00046 }
00047 
00048 PlasmaViewHost::~PlasmaViewHost() {
00049   delete d;
00050 }
00051 
00052 void PlasmaViewHost::Destroy() {
00053   delete this;
00054 }
00055 
00056 void PlasmaViewHost::SetView(ViewInterface *view) {
00057   kDebug() << "PlasmaViewHost::SetView:" << this << "," << view;
00058   if (d->view_ == view) return;
00059   d->detach();
00060   d->view_ = view;
00061 }
00062 
00063 void *PlasmaViewHost::GetNativeWidget() const {
00064   return d->widget_;
00065 }
00066 
00067 void PlasmaViewHost::ViewCoordToNativeWidgetCoord(
00068     double x, double y, double *widget_x, double *widget_y) const {
00069   double zoom = d->view_->GetGraphics()->GetZoom();
00070   if (widget_x)
00071     *widget_x = x * zoom;
00072   if (widget_y)
00073     *widget_y = y * zoom;
00074 }
00075 
00076 void PlasmaViewHost::NativeWidgetCoordToViewCoord(
00077     double x, double y, double *view_x, double *view_y) const {
00078   double zoom = d->view_->GetGraphics()->GetZoom();
00079   if (zoom == 0) return;
00080   if (view_x) *view_x = x / zoom;
00081   if (view_y) *view_y = y / zoom;
00082 }
00083 
00084 void PlasmaViewHost::QueueDraw() {
00085   d->queueDraw();
00086 }
00087 
00088 void PlasmaViewHost::QueueResize() {
00089   d->queueResize();
00090 }
00091 
00092 void PlasmaViewHost::EnableInputShapeMask(bool enable) {
00093 }
00094 
00095 void PlasmaViewHost::SetResizable(ViewInterface::ResizableMode mode) {
00096   if (d->type_ != ViewHostInterface::VIEW_HOST_MAIN || d->is_popout_ ||
00097       !d->info->applet)
00098       return;
00099   if (mode == ViewInterface::RESIZABLE_TRUE)
00100     d->info->applet->setAspectRatioMode(Plasma::IgnoreAspectRatio);
00101   else
00102     d->info->applet->setAspectRatioMode(Plasma::KeepAspectRatio);
00103   kDebug() << "SetResizable:" << mode << d->info->applet->aspectRatioMode();
00104 }
00105 
00106 void PlasmaViewHost::SetCaption(const std::string &caption) {
00107   d->caption_ = QString::fromUtf8(caption.c_str());
00108   if (d->parent_widget_)
00109     d->parent_widget_->setWindowTitle(d->caption_);
00110 }
00111 
00112 void PlasmaViewHost::SetShowCaptionAlways(bool always) {
00113   // TODO:
00114 }
00115 
00116 void PlasmaViewHost::SetCursor(ggadget::ViewInterface::CursorType type) {
00117   Qt::CursorShape shape = ggadget::qt::GetQtCursorShape(type);
00118   // Up to Qt4.4.3, There is a bug in handling cursor when
00119   // QGraphicsProxyWidget is involved.
00120   d->info->applet->setCursor(shape);
00121   if (d->widget_)
00122     d->widget_->setCursor(shape);
00123 }
00124 
00125 void PlasmaViewHost::ShowTooltip(const std::string &tooltip) {
00126   QToolTip::showText(QCursor::pos(), QString::fromUtf8(tooltip.c_str()));
00127 }
00128 
00129 void PlasmaViewHost::ShowTooltipAtPosition(const std::string &tooltip,
00130                                            double x, double y) {
00131   // TODO:
00132 }
00133 
00134 bool PlasmaViewHost::ShowView(bool modal, int flags,
00135                               Slot1<bool, int> *feedback_handler) {
00136   if (d->showView(modal, flags, feedback_handler)) {
00137     if (d->parent_widget_)
00138       d->parent_widget_->setWindowTitle(d->caption_);
00139     return true;
00140   }
00141   return false;
00142 }
00143 
00144 void PlasmaViewHost::CloseView() {
00145   d->closeView();
00146 }
00147 
00148 bool PlasmaViewHost::ShowContextMenu(int button) {
00149   return d->showContextMenu(button);
00150 }
00151 
00152 void PlasmaViewHost::Alert(const ViewInterface *view, const char *message) {
00153   KMessageBox::information(NULL,message,
00154                            view->GetCaption().c_str());
00155 }
00156 
00157 ViewHostInterface::ConfirmResponse PlasmaViewHost::Confirm(
00158     const ViewInterface *view, const char *message, bool) {
00159   int ret = KMessageBox::questionYesNo(NULL,
00160                                        message,
00161                                        view->GetCaption().c_str() );
00162   if (ret == KMessageBox::Yes)
00163     return CONFIRM_YES;
00164   else
00165     return CONFIRM_NO;
00166 }
00167 
00168 std::string PlasmaViewHost::Prompt(const ViewInterface *view,
00169                                    const char *message,
00170                                    const char *default_value) {
00171   QString s = KInputDialog::getText(view->GetCaption().c_str(),
00172                                    message);
00173   return s.toUtf8().data();
00174 }
00175 
00176 ViewHostInterface::Type PlasmaViewHost::GetType() const {
00177   return d->type_;
00178 }
00179 
00180 ViewInterface *PlasmaViewHost::GetView() const {
00181   return d->view_;
00182 }
00183 
00184 int PlasmaViewHost::GetDebugMode() const {
00185   return d->info->view_debug_mode;
00186 }
00187 
00188 GadgetInfo *PlasmaViewHost::getInfo() {
00189   return d->info;
00190 }
00191 
00192 } // namespace ggadget
00193 #include "plasma_view_host_internal.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal