25 #include <QApplication>
28 #include <QDesktopWidget>
31 #include <QGraphicsLayout>
33 #include <kwindowsystem.h>
35 #include <KIconLoader>
37 #include <Plasma/Containment>
38 #include <Plasma/Corona>
39 #include <Plasma/Theme>
40 #include <Plasma/FrameSvg>
41 #include <Plasma/Dialog>
42 #include <Plasma/WindowEffects>
48 ExplorerWindow::ExplorerWindow(
QWidget *parent)
50 m_location(Plasma::Floating),
51 m_layout(new QBoxLayout(QBoxLayout::TopToBottom, this)),
52 m_background(new Plasma::FrameSvg(this)),
60 m_background->setImagePath("dialogs/background");
61 m_background->setContainsMultipleImages(true);
63 setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
64 KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::Sticky | NET::KeepAbove);
65 setAttribute(Qt::WA_DeleteOnClose);
66 setAttribute(Qt::WA_TranslucentBackground);
67 setFocus(Qt::ActiveWindowFocusReason);
68 setLocation(Plasma::BottomEdge);
70 QPalette pal = palette();
71 pal.setBrush(backgroundRole(), Qt::transparent);
74 Plasma::WindowEffects::overrideShadow(winId(), true);
76 m_layout->setContentsMargins(0, 0, 0, 0);
78 connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(onActiveWindowChanged(WId)));
79 connect(m_background, SIGNAL(repaintNeeded()), SLOT(backgroundChanged()));
80 m_adjustViewTimer = new QTimer(this);
81 m_adjustViewTimer->setSingleShot(true);
82 connect(m_adjustViewTimer, SIGNAL(timeout()), this, SLOT(syncToGraphicsWidget()));
89 m_corona->removeOffscreenWidget(m_groupManager);
93 delete m_groupManager;
108 void ExplorerWindow::adjustSize(
int screen)
110 QSize screenSize = m_corona->screenGeometry(screen).size();
112 setMaximumSize(screenSize);
115 void ExplorerWindow::backgroundChanged()
117 Plasma::Location l = m_location;
118 m_location = Plasma::Floating;
125 if (containment == m_containment.data()) {
131 disconnect(m_containment.data(), 0,
this, 0);
137 m_corona = m_containment.data()->corona();
139 foreach (Plasma::Containment *containment, m_corona->containments()) {
140 connect(containment, SIGNAL(toolBoxToggled()),
this, SLOT(close()));
143 if (m_groupManager) {
150 return m_containment.data();
155 if (m_graphicsWidget) {
156 m_graphicsWidget->removeEventFilter(
this);
159 m_graphicsWidget = widget;
163 QVBoxLayout *lay =
new QVBoxLayout(
this);
169 m_view =
new QGraphicsView(
this);
170 m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
171 m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
172 m_view->setFrameShape(QFrame::NoFrame);
173 m_view->viewport()->setAutoFillBackground(
false);
174 layout()->addWidget(m_view);
177 m_view->setScene(widget->scene());
180 m_view->centerOn(widget);
181 if (widget->layout()) {
182 widget->layout()->activate();
184 static_cast<QGraphicsLayoutItem *
>(widget)->updateGeometry();
185 widget->resize(widget->size().expandedTo(widget->effectiveSizeHint(Qt::MinimumSize)));
187 syncToGraphicsWidget();
191 widget->installEventFilter(
this);
198 void ExplorerWindow::syncToGraphicsWidget()
200 m_adjustViewTimer->stop();
201 if (m_view && m_graphicsWidget) {
202 QSize prevSize = size();
205 int left, top, right, bottom;
206 getContentsMargins(&left, &top, &right, &bottom);
210 screenRect = m_corona->screenGeometry(m_containment.data()->screen());
214 QSize maxSize = KWindowSystem::workArea().intersect(screenRect).size();
217 if (m_location == Plasma::LeftEdge || m_location == Plasma::RightEdge) {
218 windowSize = QSize(qMin(
int(m_graphicsWidget->size().width()) + left + right, maxSize.width()), maxSize.height());
219 m_graphicsWidget->resize(m_graphicsWidget->size().width(), windowSize.height());
221 windowSize = QSize(maxSize.width(), qMin(
int(m_graphicsWidget->size().height()) + top + bottom, maxSize.height()));
222 m_graphicsWidget->resize(windowSize.width(), m_graphicsWidget->size().height());
227 setMinimumSize(windowSize);
233 QRectF sceneRect(m_graphicsWidget->sceneBoundingRect());
235 sceneRect.setWidth(qMax(qreal(1), sceneRect.width()));
236 sceneRect.setHeight(qMax(qreal(1), sceneRect.height()));
237 m_view->setSceneRect(sceneRect);
239 m_view->centerOn(m_graphicsWidget);
246 if (watched == m_graphicsWidget &&
247 (event->type() == QEvent::GraphicsSceneResize ||
event->type() == QEvent::GraphicsSceneMove)) {
248 m_adjustViewTimer->start(150);
251 return QWidget::eventFilter(watched, event);
256 if (m_location == loc) {
260 Plasma::WindowEffects::slideWindow(
this, loc);
265 case Plasma::LeftEdge:
266 m_background->setEnabledBorders(Plasma::FrameSvg::RightBorder);
267 m_layout->setDirection(QBoxLayout::TopToBottom);
268 setContentsMargins(0, 0, m_background->marginSize(Plasma::RightMargin), 0);
271 case Plasma::RightEdge:
272 m_background->setEnabledBorders(Plasma::FrameSvg::LeftBorder);
273 m_layout->setDirection(QBoxLayout::TopToBottom);
274 setContentsMargins(m_background->marginSize(Plasma::LeftMargin), 0, 0, 0);
277 case Plasma::TopEdge:
278 m_background->setEnabledBorders(Plasma::FrameSvg::BottomBorder);
279 m_layout->setDirection(QBoxLayout::BottomToTop);
280 setContentsMargins(0, 0, 0, m_background->marginSize(Plasma::BottomMargin));
283 case Plasma::BottomEdge:
285 m_background->setEnabledBorders(Plasma::FrameSvg::TopBorder);
286 m_layout->setDirection(QBoxLayout::TopToBottom);
287 setContentsMargins(0, m_background->marginSize(Plasma::TopMargin), 0, 0);
291 if (m_groupManager) {
302 screen = m_containment.data()->screen();
307 QRect screenGeom = m_corona->screenGeometry(screen);
309 switch (m_location) {
310 case Plasma::LeftEdge:
311 return QPoint(panelGeom.right(), screenGeom.top());
313 case Plasma::RightEdge:
314 return QPoint(panelGeom.left() - width(), screenGeom.top());
316 case Plasma::TopEdge:
317 return QPoint(screenGeom.left(), panelGeom.bottom());
319 case Plasma::BottomEdge:
321 return QPoint(screenGeom.left(), panelGeom.top() - height());
333 if (m_location == Plasma::LeftEdge || m_location == Plasma::RightEdge) {
337 return Qt::Horizontal;
343 if (!m_groupManager) {
346 m_corona->addOffscreenWidget(m_groupManager);
347 m_groupManager->show();
352 m_groupManager->resize(width(), m_groupManager->size().height());
354 m_groupManager->resize(m_groupManager->size().width(), height());
357 m_groupManager->
setIconSize(KIconLoader::SizeHuge);
361 connect(m_groupManager, SIGNAL(closeClicked()),
this, SLOT(close()));
364 m_groupManager->show();
372 return m_view && m_view->isVisible();
380 void ExplorerWindow::onActiveWindowChanged(WId
id)
386 if (QApplication::activeWindow() == 0 || (QApplication::activeWindow()->winId() != KWindowSystem::activeWindow())) {
387 if (m_view && m_view->isVisible() && !isActiveWindow()) {
397 QPainter painter(
this);
398 painter.setCompositionMode(QPainter::CompositionMode_Source );
400 m_background->paintFrame(&painter);
405 if (event->key() == Qt::Key_Escape) {
412 m_background->resizeFrame(size());
414 Plasma::WindowEffects::enableBlurBehind(effectiveWinId(),
true, m_background->mask());
416 qDebug() <<
"ExplorerWindow::resizeEvent" <<
event->oldSize()<<
event->size();
418 QWidget::resizeEvent(event);
421 #include "explorerwindow.moc"
void paintEvent(QPaintEvent *event)
Plasma::FrameSvg * background() const
Plasma::Location location() const
void setLocation(Plasma::Location location)
set orientation
void setIconSize(int size)
Sets the icon size.
void setGraphicsWidget(QGraphicsWidget *widget)
void setContainment(Plasma::Containment *containment)
Changes the current containment you've got to call this at least once so that it can access the coron...
virtual void setLocation(const Plasma::Location &loc)
static ExplorerWindow * instance()
void resizeEvent(QResizeEvent *event)
bool eventFilter(QObject *watched, QEvent *event)
void keyPressEvent(QKeyEvent *event)
Qt::Orientation orientation() const
Plasma::Containment * containment() const
virtual void setContainment(Plasma::Containment *containment)
QPoint positionForPanelGeometry(const QRect &panelGeom) const
bool isControllerViewVisible() const