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

Plasma

plasma_view_host_internal.h

Go to the documentation of this file.
00001 /*
00002   Copyright 2008 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 #ifndef HOSTS_PLASMA_VIEW_HOST_INTERNAL_H__
00018 #define HOSTS_PLASMA_VIEW_HOST_INTERNAL_H__
00019 #include <Plasma/Dialog>
00020 #include <Plasma/Applet>
00021 #include <ggadget/qt/qt_menu.h>
00022 #include <ggadget/view_interface.h>
00023 #include <ggadget/qt/utilities.h>
00024 #include <QDialogButtonBox>
00025 #include <QVBoxLayout>
00026 namespace ggadget{
00027 
00028 class PlasmaViewHost::Private : public QObject {
00029   Q_OBJECT
00030  public:
00031   Private(GadgetInfo *i, Type type, bool popout)
00032     : view_(NULL),
00033       parent_widget_(NULL),
00034       widget_(NULL),
00035       type_(type),
00036       info(i),
00037       is_popout_(popout),
00038       gadget_w_(0),
00039       gadget_h_(0),
00040       feedback_handler_(NULL) {}
00041 
00042   ~Private() {
00043     closeView();
00044   }
00045 
00046   static void embedWidget(QGraphicsWidget *parent, QWidget *widget) {
00047     widget->setAttribute(Qt::WA_NoSystemBackground);
00048     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(parent);
00049     layout->setSpacing(0);
00050     QGraphicsProxyWidget* proxy = new QGraphicsProxyWidget(parent);
00051     proxy->setWidget(widget);
00052     layout->addItem(proxy);
00053     parent->setLayout(layout);
00054     DLOG("EmbededWidget: widget:%p, applet:%p, layout:%p, proxy:%p",
00055          widget, parent, layout, proxy);
00056   }
00057 
00058   /* Show the view in right place
00059    *    - floating main view: Shown within the applet
00060    *    - popouted main view and details view: Shown in QtViewWidget
00061    */
00062   bool showView(bool modal, int flags, Slot1<bool, int> *feedback_handler) {
00063     ASSERT(view_);
00064     if (feedback_handler_ && feedback_handler_ != feedback_handler)
00065       delete feedback_handler_;
00066     feedback_handler_ = feedback_handler;
00067 
00068     if (widget_) return true;
00069 
00070     if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_) {
00071       // normal main view
00072       if (info->widget == NULL) {
00073         widget_ = new QtViewWidget(view_, 0);
00074         embedWidget(info->applet, widget_);
00075         info->widget = widget_;
00076       } else {
00077         widget_ = info->widget;
00078         widget_->SetView(view_);
00079         adjustAppletSize();
00080       }
00081       info->applet->setBackgroundHints(Plasma::Applet::NoBackground);
00082       if (info->applet->location() == Plasma::Floating) {
00083         connect(widget_, SIGNAL(moved(int, int)),
00084                 this, SLOT(onViewMoved(int, int)));
00085       } else {
00086         disconnect();
00087       }
00088 
00089       if (info->applet->formFactor() == Plasma::Vertical)
00090         view_->SetWidth(info->applet->size().width());
00091       if (info->applet->formFactor() == Plasma::Horizontal)
00092         view_->SetHeight(info->applet->size().height());
00093     } else {
00094       // Popouted main view and details view
00095       widget_ = new QtViewWidget(view_, QtViewWidget::FLAG_MOVABLE);
00096       parent_widget_ = widget_;
00097       SetGadgetWindowIcon(widget_, view_->GetGadget());
00098       if (info->expanded_main_view_host
00099           && type_ == ViewHostInterface::VIEW_HOST_DETAILS) {
00100         int w = view_->GetWidth();
00101         int h = view_->GetHeight();
00102         QWidget *expanded =
00103             static_cast<QWidget*>(info->expanded_main_view_host->GetNativeWidget());
00104         QPoint p = ggadget::qt::GetPopupPosition(expanded->geometry(), QSize(w, h));
00105         widget_->move(p);
00106       } else {
00107         widget_->move(info->applet->popupPosition(widget_->sizeHint()));
00108       }
00109       widget_->show();
00110     }
00111     return true;
00112   }
00113 
00114   void closeView() {
00115     kDebug() << "CloseView";
00116     if (parent_widget_) {
00117       delete parent_widget_;
00118       parent_widget_ = NULL;
00119       widget_ = NULL;
00120     } else {
00121       if (info->applet && widget_) {
00122         // widget_ is owned by applet, so if applet is null, widget_ is
00123         // destroyed already
00124         widget_->SetView(NULL);
00125       }
00126       widget_ = NULL;
00127     }
00128   }
00129 
00130   void queueDraw() {
00131     if (parent_widget_)
00132       parent_widget_->update();
00133     else if (info->applet)
00134       info->applet->update();
00135   }
00136 
00137   // This is called when view size has changed, caused by constraintsEvent or
00138   // user manually resizes gadget. Applet and widget size will be adjusted
00139   // according to view size.
00140   void adjustAppletSize() {
00141     if (!info->main_view_host || !info->applet) return;
00142     ViewInterface *view = info->main_view_host->GetViewDecorator();
00143     double w = view->GetWidth();
00144     double h = view->GetHeight();
00145     if (w <= 0 || h <= 0) return;
00146     if (gadget_w_ == w && gadget_h_ == h) return;
00147 
00148     gadget_w_ = w;
00149     gadget_h_ = h;
00150     kDebug() << "view size:" << w << " " << h;
00151 
00152     kDebug() << "applet old size:" << info->applet->size();
00153     if (info->applet->location() == Plasma::Floating) {
00154       info->applet->resize(w, h);
00155     } else {
00156       if (isHorizontal(info->applet->location()))
00157         info->applet->setMaximumWidth(w);
00158       else
00159         info->applet->setMaximumHeight(h);
00160     }
00161     kDebug() << "applet new size:" << info->applet->size();
00162 
00163     if (widget_) {
00164       kDebug() << "widget old size:" << widget_->size();
00165       widget_->resize(w, h);
00166       kDebug() << "widget new size:" << widget_->size();
00167     }
00168   }
00169 
00170   void queueResize() {
00171     if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_) {
00172       adjustAppletSize();
00173     } else if (widget_) {
00174       widget_->AdjustToViewSize();
00175     }
00176   }
00177 
00178   bool showContextMenu(int button) {
00179     ASSERT(view_);
00180     Q_UNUSED(button);
00181     context_menu_.clear();
00182     QtMenu qt_menu(&context_menu_);
00183     view_->OnAddContextMenuItems(&qt_menu);
00184     if (!context_menu_.isEmpty()) {
00185       context_menu_.popup(QCursor::pos());
00186       return true;
00187     } else {
00188       return false;
00189     }
00190   }
00191 
00192   ViewInterface *view_;
00193   QWidget *parent_widget_;
00194   QtViewWidget *widget_;
00195   ViewHostInterface::Type type_;
00196   GadgetInfo *info;
00197   bool is_popout_;
00198   double gadget_w_;
00199   double gadget_h_;
00200 
00201   Slot1<bool, int> *feedback_handler_;
00202   QString caption_;
00203   QMenu context_menu_;
00204 
00205   void detach() {
00206     view_ = NULL;
00207   }
00208 
00209  public slots:
00210   void onViewMoved(int x, int y) {
00211     if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_ &&
00212         info->applet->immutability() == Plasma::Mutable)
00213       info->applet->moveBy(x, y);
00214   }
00215 };
00216 
00217 } // namespace ggadget
00218 
00219 #endif

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