Plasma
plasma_view_host_internal.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 feedback_handler_(NULL) {}
00039
00040 ~Private() {
00041 closeView();
00042 delete feedback_handler_;
00043 }
00044
00045
00046
00047
00048
00049
00050 bool showView(bool modal, int flags, Slot1<bool, int> *feedback_handler) {
00051
00052 Q_UNUSED(modal);
00053 Q_UNUSED(flags);
00054
00055 ASSERT(view_);
00056 if (feedback_handler_ != feedback_handler) {
00057 delete feedback_handler_;
00058 feedback_handler_ = feedback_handler;
00059 }
00060
00061 if (widget_) return true;
00062
00063 if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_) {
00064
00065 if (info->main_view_widget == NULL) {
00066 widget_ = new QtViewWidget(view_, 0);
00067 widget_->setAttribute(Qt::WA_NoSystemBackground);
00068 info->proxy = new QGraphicsProxyWidget(info->applet);
00069 info->proxy->setWidget(widget_);
00070 widget_->show();
00071 info->main_view_widget = widget_;
00072 } else {
00073 widget_ = info->main_view_widget;
00074 widget_->SetView(view_);
00075 adjustAppletSize();
00076 }
00077 info->applet->setBackgroundHints(Plasma::Applet::NoBackground);
00078 if (info->applet->location() == Plasma::Floating) {
00079 connect(widget_, SIGNAL(moved(int, int)),
00080 this, SLOT(onViewMoved(int, int)));
00081 } else {
00082 disconnect();
00083 }
00084 } else {
00085
00086 widget_ = new QtViewWidget(view_, QtViewWidget::FLAG_MOVABLE);
00087 parent_widget_ = widget_;
00088 SetGadgetWindowIcon(widget_, view_->GetGadget());
00089 if (info->expanded_main_view_host &&
00090 type_ == ViewHostInterface::VIEW_HOST_DETAILS) {
00091 int w = view_->GetWidth();
00092 int h = view_->GetHeight();
00093 QWidget *expanded =
00094 static_cast<QWidget*>(info->expanded_main_view_host->GetNativeWidget());
00095 QPoint p = ggadget::qt::GetPopupPosition(expanded->geometry(), QSize(w, h));
00096 widget_->move(p);
00097 } else {
00098 widget_->move(info->applet->popupPosition(widget_->sizeHint()));
00099 }
00100 widget_->show();
00101 }
00102 return true;
00103 }
00104
00105 void closeView() {
00106 kDebug() << "CloseView";
00107 if (parent_widget_) {
00108 delete parent_widget_;
00109 parent_widget_ = NULL;
00110 widget_ = NULL;
00111 } else {
00112 if (info->applet && widget_) {
00113
00114
00115 widget_->SetView(NULL);
00116 }
00117 widget_ = NULL;
00118 }
00119 }
00120
00121 void queueDraw() {
00122 if (parent_widget_) {
00123 parent_widget_->update();
00124 } else if (info->applet) {
00125 info->applet->update();
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 void adjustAppletSize() {
00136 if (!info->main_view_host || !info->applet || !info->proxy || !widget_) {
00137 return;
00138 }
00139 ViewInterface *view = info->main_view_host->GetViewDecorator();
00140 double w = view->GetWidth();
00141 double h = view->GetHeight();
00142 if (w <= 0 || h <= 0) return;
00143
00144 kDebug() << "view size:" << w << " " << h;
00145 kDebug() << "applet old size:" << info->applet->size();
00146 kDebug() << "widget old size:" << widget_->size();
00147 kDebug() << "proxy old size:" << info->proxy->size();
00148
00149 info->applet->resize(w, h);
00150 info->proxy->resize(w, h);
00151 widget_->resize(w, h);
00152
00153 kDebug() << "applet new size:" << info->applet->size();
00154 kDebug() << "widget new size:" << widget_->size();
00155 kDebug() << "proxy new size:" << info->proxy->size();
00156 }
00157
00158 void queueResize() {
00159 if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_) {
00160 adjustAppletSize();
00161 } else if (widget_) {
00162 widget_->AdjustToViewSize();
00163 }
00164 }
00165
00166 bool showContextMenu(int button) {
00167 ASSERT(view_);
00168 Q_UNUSED(button);
00169 context_menu_.clear();
00170 QtMenu qt_menu(&context_menu_);
00171 view_->OnAddContextMenuItems(&qt_menu);
00172 if (!context_menu_.isEmpty()) {
00173 context_menu_.popup(QCursor::pos());
00174 return true;
00175 } else {
00176 return false;
00177 }
00178 }
00179
00180 ViewInterface *view_;
00181 QWidget *parent_widget_;
00182 QtViewWidget *widget_;
00183 ViewHostInterface::Type type_;
00184 GadgetInfo *info;
00185 bool is_popout_;
00186
00187 Slot1<bool, int> *feedback_handler_;
00188 QString caption_;
00189 QMenu context_menu_;
00190
00191 private slots:
00192 void onViewMoved(int x, int y) {
00193 if (type_ == ViewHostInterface::VIEW_HOST_MAIN && !is_popout_ &&
00194 info->applet->immutability() == Plasma::Mutable)
00195 info->applet->moveBy(x, y);
00196 }
00197 };
00198
00199 }
00200
00201 #endif