diff --git a/tabbox/declarative.cpp b/tabbox/declarative.cpp index 3bdcfac80..b4d615178 100644 --- a/tabbox/declarative.cpp +++ b/tabbox/declarative.cpp @@ -1,371 +1,386 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ // own #include "declarative.h" #include "tabboxhandler.h" #include "clientmodel.h" // Qt #include #include #include #include #include #include #include // include KDE #include #include #include #include #include #include #include #include #include // KWin #include "thumbnailitem.h" #include #include "../client.h" #include "../workspace.h" namespace KWin { namespace TabBox { ImageProvider::ImageProvider(QAbstractItemModel *model) : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) , m_model(model) { } QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { bool ok = false; QStringList parts = id.split('/'); const int row = parts.first().toInt(&ok); if (!ok) { return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize); } const QModelIndex index = m_model->index(row, 0); if (!index.isValid()) { return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize); } TabBoxClient* client = static_cast< TabBoxClient* >(index.model()->data(index, ClientModel::ClientRole).value()); if (!client) { return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize); } QSize s(32, 32); if (requestedSize.isValid()) { s = requestedSize; } *size = s; QPixmap icon = client->icon(s); if (s.width() > icon.width() || s.height() > icon.height()) { // icon is smaller than what we requested - QML would scale it which looks bad QPixmap temp(s); temp.fill(Qt::transparent); QPainter p(&temp); p.drawPixmap(s.width()/2 - icon.width()/2, s.height()/2 - icon.height()/2, icon); icon = temp; } if (parts.size() > 2) { KIconEffect *effect = KIconLoader::global()->iconEffect(); KIconLoader::States state = KIconLoader::DefaultState; if (parts.at(2) == QLatin1String("selected")) { state = KIconLoader::ActiveState; } else if (parts.at(2) == QLatin1String("disabled")) { state = KIconLoader::DisabledState; } icon = effect->apply(icon, KIconLoader::Desktop, state); } return icon; } DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent) : QDeclarativeView(parent) , m_model(model) , m_mode(mode) , m_currentScreenGeometry() , m_frame(new Plasma::FrameSvg(this)) , m_currentLayout() , m_cachedWidth(0) , m_cachedHeight(0) { setAttribute(Qt::WA_TranslucentBackground); setWindowFlags(Qt::X11BypassWindowManagerHint); if (tabBox->embedded()) { setResizeMode(QDeclarativeView::SizeRootObjectToView); } else { setResizeMode(QDeclarativeView::SizeViewToRootObject); } QPalette pal = palette(); pal.setColor(backgroundRole(), Qt::transparent); setPalette(pal); foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) { engine()->addImportPath(importPath); } engine()->addImageProvider(QLatin1String("client"), new ImageProvider(model)); KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); kdeclarative.setupBindings(); qmlRegisterType("org.kde.kwin", 0, 1, "ThumbnailItem"); rootContext()->setContextProperty("viewId", static_cast(winId())); if (m_mode == TabBoxConfig::ClientTabBox) { rootContext()->setContextProperty("clientModel", model); } else if (m_mode == TabBoxConfig::DesktopTabBox) { rootContext()->setContextProperty("clientModel", model); } setSource(QUrl(KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + QLatin1String("/tabbox/tabbox.qml")))); // FrameSvg m_frame->setImagePath("dialogs/background"); m_frame->setCacheAllRenderedFrames(true); m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders); connect(tabBox, SIGNAL(configChanged()), SLOT(updateQmlSource())); if (m_mode == TabBoxConfig::ClientTabBox) { connect(tabBox, SIGNAL(embeddedChanged(bool)), SLOT(slotEmbeddedChanged(bool))); } } void DeclarativeView::showEvent(QShowEvent *event) { #ifndef TABBOX_KCM if (tabBox->embedded()) { Client *c = Workspace::self()->findClient(WindowMatchPredicate(tabBox->embedded())); if (c) { connect(c, SIGNAL(geometryChanged()), this, SLOT(slotUpdateGeometry())); } } #endif updateQmlSource(); m_currentScreenGeometry = QApplication::desktop()->screenGeometry(tabBox->activeScreen()); rootObject()->setProperty("screenWidth", m_currentScreenGeometry.width()); rootObject()->setProperty("screenHeight", m_currentScreenGeometry.height()); rootObject()->setProperty("allDesktops", tabBox->config().tabBoxMode() == TabBoxConfig::ClientTabBox && tabBox->config().clientDesktopMode() == TabBoxConfig::AllDesktopsClients); if (ClientModel *clientModel = qobject_cast(m_model)) { rootObject()->setProperty("longestCaption", clientModel->longestCaption()); } if (QObject *item = rootObject()->findChild("listView")) { item->setProperty("currentIndex", tabBox->first().row()); connect(item, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int))); } slotUpdateGeometry(); QGraphicsView::showEvent(event); } void DeclarativeView::resizeEvent(QResizeEvent *event) { - m_frame->resizeFrame(event->size()); - if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled() && !tabBox->embedded()) { - // blur background - Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask()); - Plasma::WindowEffects::overrideShadow(winId(), true); - } else if (tabBox->embedded()) { + if (tabBox->embedded()) { Plasma::WindowEffects::enableBlurBehind(winId(), false); } else { - // do not trim to mask with compositing enabled, otherwise shadows are cropped - setMask(m_frame->mask()); + const QString maskImagePath = rootObject()->property("maskImagePath").toString(); + if (maskImagePath.isEmpty()) { + clearMask(); + Plasma::WindowEffects::enableBlurBehind(winId(), false); + } else { + const double maskWidth = rootObject()->property("maskWidth").toDouble(); + const double maskHeight = rootObject()->property("maskHeight").toDouble(); + const int maskTopMargin = rootObject()->property("maskTopMargin").toInt(); + const int maskLeftMargin = rootObject()->property("maskLeftMargin").toInt(); + m_frame->setImagePath(maskImagePath); + m_frame->resizeFrame(QSizeF(maskWidth, maskHeight)); + QRegion mask = m_frame->mask().translated(maskLeftMargin, maskTopMargin); + if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) { + // blur background + Plasma::WindowEffects::enableBlurBehind(winId(), true, mask); + Plasma::WindowEffects::overrideShadow(winId(), true); + clearMask(); + } else { + // do not trim to mask with compositing enabled, otherwise shadows are cropped + setMask(mask); + } + } } QDeclarativeView::resizeEvent(event); } void DeclarativeView::hideEvent(QHideEvent *event) { QWidget::hideEvent(event); #ifndef TABBOX_KCM if (tabBox->embedded()) { Client *c = Workspace::self()->findClient(WindowMatchPredicate(tabBox->embedded())); if (c) { disconnect(c, SIGNAL(geometryChanged()), this, SLOT(slotUpdateGeometry())); } } #endif } bool DeclarativeView::x11Event(XEvent *e) { if (tabBox->embedded() && (e->type == ButtonPress || e->type == ButtonRelease || e->type == MotionNotify)) { XEvent ev; memcpy(&ev, e, sizeof(ev)); if (e->type == ButtonPress || e->type == ButtonRelease) { ev.xbutton.x += m_relativePos.x(); ev.xbutton.y += m_relativePos.y(); ev.xbutton.window = tabBox->embedded(); } else if (e->type == MotionNotify) { ev.xmotion.x += m_relativePos.x(); ev.xmotion.y += m_relativePos.y(); ev.xmotion.window = tabBox->embedded(); } XSendEvent( QX11Info::display(), tabBox->embedded(), False, NoEventMask, &ev ); } return QDeclarativeView::x11Event(e); } void DeclarativeView::slotUpdateGeometry() { const WId embeddedId = tabBox->embedded(); if (embeddedId != 0) { const KWindowInfo info = KWindowSystem::windowInfo(embeddedId, NET::WMGeometry); const Qt::Alignment alignment = tabBox->embeddedAlignment(); const QPoint offset = tabBox->embeddedOffset(); int x = info.geometry().left(); int y = info.geometry().top(); int width = tabBox->embeddedSize().width(); int height = tabBox->embeddedSize().height(); if (alignment.testFlag(Qt::AlignLeft) || alignment.testFlag(Qt::AlignHCenter)) { x += offset.x(); } if (alignment.testFlag(Qt::AlignRight)) { x = x + info.geometry().width() - offset.x() - width; } if (alignment.testFlag(Qt::AlignHCenter)) { width = info.geometry().width() - 2 * offset.x(); } if (alignment.testFlag(Qt::AlignTop) || alignment.testFlag(Qt::AlignVCenter)) { y += offset.y(); } if (alignment.testFlag(Qt::AlignBottom)) { y = y + info.geometry().height() - offset.y() - height; } if (alignment.testFlag(Qt::AlignVCenter)) { height = info.geometry().height() - 2 * offset.y(); } setGeometry(QRect(x, y, width, height)); m_relativePos = QPoint(info.geometry().x(), info.geometry().x()); } else { const int width = rootObject()->property("width").toInt(); const int height = rootObject()->property("height").toInt(); setGeometry(m_currentScreenGeometry.x() + static_cast(m_currentScreenGeometry.width()) * 0.5 - static_cast(width) * 0.5, m_currentScreenGeometry.y() + static_cast(m_currentScreenGeometry.height()) * 0.5 - static_cast(height) * 0.5, width, height); m_relativePos = pos(); } } void DeclarativeView::setCurrentIndex(const QModelIndex &index, bool disableAnimation) { if (tabBox->config().tabBoxMode() != m_mode) { return; } if (QObject *item = rootObject()->findChild("listView")) { QVariant durationRestore; if (disableAnimation) { durationRestore = item->property("highlightMoveDuration"); item->setProperty("highlightMoveDuration", QVariant(1)); } item->setProperty("currentIndex", index.row()); if (disableAnimation) { item->setProperty("highlightMoveDuration", durationRestore); } } } void DeclarativeView::currentIndexChanged(int row) { tabBox->setCurrentIndex(m_model->index(row, 0)); KWindowSystem::forceActiveWindow(m_model->data(m_model->index(row, 0), ClientModel::WIdRole).toLongLong()); } void DeclarativeView::updateQmlSource(bool force) { if (tabBox->config().tabBoxMode() != m_mode) { return; } if (!force && tabBox->config().layoutName() == m_currentLayout) { return; } if (m_mode == TabBoxConfig::DesktopTabBox) { m_currentLayout = tabBox->config().layoutName(); const QString file = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + QLatin1String("/tabbox/desktop.qml")); rootObject()->setProperty("source", QUrl(file)); return; } QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(tabBox->config().layoutName()); KService::List offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint); if (offers.isEmpty()) { // load default constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg("informative"); offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint); if (offers.isEmpty()) { kDebug(1212) << "could not find default window switcher layout"; return; } } m_currentLayout = tabBox->config().layoutName(); KService::Ptr service = offers.first(); const QString pluginName = service->property("X-KDE-PluginInfo-Name").toString(); if (service->property("X-Plasma-API").toString() != "declarativeappletscript") { kDebug(1212) << "Window Switcher Layout is no declarativeappletscript"; return; } const QString scriptName = service->property("X-Plasma-MainScript").toString(); const QString file = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/tabbox/" + pluginName + "/contents/" + scriptName); if (file.isNull()) { kDebug(1212) << "Could not find QML file for window switcher"; return; } rootObject()->setProperty("source", QUrl(file)); } void DeclarativeView::slotEmbeddedChanged(bool enabled) { if (enabled) { // cache the width setResizeMode(QDeclarativeView::SizeRootObjectToView); m_cachedWidth = rootObject()->property("width").toInt(); m_cachedHeight = rootObject()->property("height").toInt(); } else { setResizeMode(QDeclarativeView::SizeViewToRootObject); if (m_cachedWidth != 0 && m_cachedHeight != 0) { rootObject()->setProperty("width", m_cachedWidth); rootObject()->setProperty("height", m_cachedHeight); } updateQmlSource(true); } } void DeclarativeView::slotWindowChanged(WId wId, unsigned int properties) { if (wId != tabBox->embedded()) { return; } if (properties & NET::WMGeometry) { slotUpdateGeometry(); } } bool DeclarativeView::sendKeyEvent(QKeyEvent *e) { return event(e); } } // namespace TabBox } // namespace KWin diff --git a/tabbox/qml/CMakeLists.txt b/tabbox/qml/CMakeLists.txt index d4bc863ec..bda7d8b95 100644 --- a/tabbox/qml/CMakeLists.txt +++ b/tabbox/qml/CMakeLists.txt @@ -1,26 +1,30 @@ install( FILES tabbox.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( FILES desktop.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) # packages install( DIRECTORY clients/big_icons DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/compact DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/informative DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/present_windows DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/small_icons DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/text DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/thumbnails DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/window_strip DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) # service files install( FILES clients/big_icons/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_big_icons.desktop ) install( FILES clients/compact/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_compact.desktop ) install( FILES clients/informative/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_informative.desktop ) install( FILES clients/present_windows/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_present_windows.desktop ) install( FILES clients/small_icons/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_small_icons.desktop ) install( FILES clients/text/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_text.desktop ) install( FILES clients/thumbnails/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_thumbnails.desktop ) install( FILES clients/window_strip/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_window_strip.desktop ) -# install additional icon tabbox into those that need it -install (FILES IconTabBox.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/big_icons/contents/ui) -install (FILES IconTabBox.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/small_icons/contents/ui) +install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/big_icons/contents/ui) +install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/small_icons/contents/ui) +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/compact/contents/ui) +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/informative/contents/ui) +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/present_windows/contents/ui) +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/thumbnails/contents/ui) +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/text/contents/ui) diff --git a/tabbox/qml/IconTabBox.qml b/tabbox/qml/IconTabBox.qml index 23bb11b16..fd9b752cc 100644 --- a/tabbox/qml/IconTabBox.qml +++ b/tabbox/qml/IconTabBox.qml @@ -1,124 +1,126 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: iconsTabBox property int iconSize property int imagePathPrefix: (new Date()).getTime() property alias count: iconsListView.count property alias margins: hoverItem.margins property alias currentItem: iconsListView.currentItem focus: true function setModel(model) { iconsListView.model = model; iconsListView.imageId++; } function modelChanged() { iconsListView.imageId++; } PlasmaCore.Theme { id: theme } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } // delegate Component { id: listDelegate Item { property alias data: iconItem.data id: delegateItem width: iconSize + hoverItem.margins.left + hoverItem.margins.right height: iconSize + hoverItem.margins.top + hoverItem.margins.bottom Image { property variant data: model id: iconItem source: "image://client/" + index + "/" + iconsTabBox.imagePathPrefix + "-" + iconsListView.imageId + (index == iconsListView.currentIndex ? "/selected" : "") sourceSize { width: iconSize height: iconSize } anchors { fill: parent leftMargin: hoverItem.margins.left rightMargin: hoverItem.margins.right topMargin: hoverItem.margins.top bottomMargin: hoverItem.margins.bottom } } MouseArea { anchors.fill: parent onClicked: { iconsListView.currentIndex = index; iconsListView.currentIndexChanged(iconsListView.currentIndex); } } } } ListView { signal currentIndexChanged(int index) id: iconsListView objectName: "listView" orientation: ListView.Horizontal // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 + width: (iconSize + margins.left + margins.right) * count + height: iconSize + margins.top + margins.bottom anchors { - fill: parent + horizontalCenter: parent.horizontalCenter } clip: true delegate: listDelegate highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: iconSize + margins.left + margins.right height: iconSize + margins.top + margins.bottom } highlightMoveDuration: 250 boundsBehavior: Flickable.StopAtBounds } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Left) { iconsListView.decrementCurrentIndex(); iconsListView.currentIndexChanged(iconsListView.currentIndex); } else if (event.key == Qt.Key_Right) { iconsListView.incrementCurrentIndex(); iconsListView.currentIndexChanged(iconsListView.currentIndex); } } } diff --git a/tabbox/qml/clients/big_icons/contents/ui/main.qml b/tabbox/qml/clients/big_icons/contents/ui/main.qml index 7115b7f4d..4a3666d2b 100644 --- a/tabbox/qml/clients/big_icons/contents/ui/main.qml +++ b/tabbox/qml/clients/big_icons/contents/ui/main.qml @@ -1,112 +1,115 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: bigIconsTabBox property int screenWidth : 0 property int screenHeight : 0 property int imagePathPrefix: (new Date()).getTime() - property int optimalWidth: (icons.iconSize + icons.margins.left + icons.margins.right) * icons.count + background.margins.left + background.margins.bottom - property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.margins.top + background.margins.bottom + 40 + property int optimalWidth: (icons.iconSize + icons.margins.left + icons.margins.right) * icons.count + background.leftMargin + background.bottomMargin + property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.topMargin + background.bottomMargin + 40 property bool canStretchX: false property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.3, optimalWidth), screenWidth * 0.9) height: Math.min(Math.max(screenHeight * 0.05, optimalHeight), screenHeight * 0.5) function setModel(model) { icons.setModel(model); } function modelChanged() { icons.modelChanged(); } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } IconTabBox { id: icons iconSize: 128 - height: iconSize + background.margins.top + background.margins.bottom + height: iconSize + background.topMargin + icons.margins.top + icons.margins.bottom anchors { top: parent.top left: parent.left right: parent.right - topMargin: background.margins.top - rightMargin: background.margins.right - bottomMargin: background.margins.bottom - leftMargin: background.margins.left + topMargin: background.topMargin + rightMargin: background.rightMargin + leftMargin: background.leftMargin } } Item { id: captionFrame anchors { top: icons.bottom left: parent.left right: parent.right bottom: parent.bottom - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } Text { function constrainWidth() { if (textItem.width > textItem.maxWidth && textItem.width > 0 && textItem.maxWidth > 0) { textItem.width = textItem.maxWidth; } else { textItem.width = undefined; } } function calculateMaxWidth() { textItem.maxWidth = bigIconsTabBox.width - captionFrame.anchors.leftMargin - captionFrame.anchors.rightMargin - captionFrame.anchors.rightMargin; } id: textItem property int maxWidth: 0 text: icons.currentItem ? icons.currentItem.data.caption : "" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: theme.textColor elide: Text.ElideMiddle font { bold: true } anchors { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } onTextChanged: textItem.constrainWidth() Component.onCompleted: textItem.calculateMaxWidth() Connections { target: bigIconsTabBox onWidthChanged: { textItem.calculateMaxWidth(); textItem.constrainWidth(); } } } } } diff --git a/tabbox/qml/clients/compact/contents/ui/main.qml b/tabbox/qml/clients/compact/contents/ui/main.qml index 1f6f03679..14fca297c 100644 --- a/tabbox/qml/clients/compact/contents/ui/main.qml +++ b/tabbox/qml/clients/compact/contents/ui/main.qml @@ -1,210 +1,214 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: compactTabBox property int screenWidth : 0 property int screenHeight : 0 property string longestCaption: "" property int imagePathPrefix: (new Date()).getTime() property int optimalWidth: compactListView.maxRowWidth - property int optimalHeight: compactListView.rowHeight * compactListView.count + background.margins.top + background.margins.bottom + property int optimalHeight: compactListView.rowHeight * compactListView.count + background.topMargin + background.bottomMargin property bool canStretchX: true property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.2, optimalWidth), screenWidth * 0.8) height: Math.min(Math.max(screenHeight * 0.2, optimalHeight), screenHeight * 0.8) focus: true property int textMargin: 2 onLongestCaptionChanged: { compactListView.maxRowWidth = compactListView.calculateMaxRowWidth(); } function setModel(model) { compactListView.model = model; compactListView.maxRowWidth = compactListView.calculateMaxRowWidth(); compactListView.imageId++; } function modelChanged() { compactListView.imageId++; } /** * Returns the caption with adjustments for minimized items. * @param caption the original caption * @param mimized whether the item is minimized * @return Caption adjusted for minimized state **/ function itemCaption(caption, minimized) { var text = caption; if (minimized) { text = "(" + text + ")"; } return text; } PlasmaCore.Theme { id: theme } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } // delegate Component { id: listDelegate Item { id: delegateItem width: compactListView.width height: compactListView.rowHeight opacity: minimized ? 0.6 : 1.0 Image { id: iconItem source: "image://client/" + index + "/" + compactTabBox.imagePathPrefix + "-" + compactListView.imageId + "/selected" width: 16 height: 16 sourceSize { width: 16 height: 16 } anchors { verticalCenter: parent.verticalCenter left: parent.left leftMargin: hoverItem.margins.left } } Text { id: captionItem horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignBottom text: itemCaption(caption, minimized) font.bold: index == compactListView.currentIndex color: theme.textColor elide: Text.ElideMiddle anchors { left: iconItem.right right: parent.right top: parent.top bottom: parent.bottom topMargin: hoverItem.margins.top rightMargin: hoverItem.margins.right bottomMargin: hoverItem.margins.bottom leftMargin: 2 * compactTabBox.textMargin } } MouseArea { anchors.fill: parent onClicked: { compactListView.currentIndex = index; compactListView.currentIndexChanged(compactListView.currentIndex); } } } } ListView { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "' + itemCaption(compactTabBox.longestCaption, true) + '"\n' + ' font.bold: true\n' + ' visible: false\n' + '}', compactListView, "calculateMaxRowWidth"); width = Math.max(textElement.width, width); textElement.destroy(); - return width + 16 + 2 * compactTabBox.textMargin + hoverItem.margins.right + hoverItem.margins.left + background.margins.left + background.margins.right; + return width + 16 + 2 * compactTabBox.textMargin + hoverItem.margins.right + hoverItem.margins.left + background.leftMargin + background.right;Margin } /** * Calculates the height of one row based on the text height and icon size. * @return Row height **/ function calcRowHeight() { var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "Some Text"\n' + ' font.bold: true\n' + ' visible: false\n' + '}', compactListView, "calcRowHeight"); var height = textElement.height; textElement.destroy(); // icon size or two text elements and margins and hoverItem margins return Math.max(16, height + hoverItem.margins.top + hoverItem.margins.bottom); } signal currentIndexChanged(int index) id: compactListView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background property int maxRowWidth: calculateMaxRowWidth() property int rowHeight: calcRowHeight() // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 anchors { fill: parent - topMargin: background.margins.top - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + topMargin: background.topMargin + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } clip: true delegate: listDelegate highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: compactListView.width } highlightMoveDuration: 250 boundsBehavior: Flickable.StopAtBounds } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Up) { compactListView.decrementCurrentIndex(); compactListView.currentIndexChanged(compactListView.currentIndex); } else if (event.key == Qt.Key_Down) { compactListView.incrementCurrentIndex(); compactListView.currentIndexChanged(compactListView.currentIndex); } } } diff --git a/tabbox/qml/clients/informative/contents/ui/main.qml b/tabbox/qml/clients/informative/contents/ui/main.qml index 3a2c4a3e9..5e3f9a6f2 100644 --- a/tabbox/qml/clients/informative/contents/ui/main.qml +++ b/tabbox/qml/clients/informative/contents/ui/main.qml @@ -1,226 +1,230 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: informativeTabBox property int screenWidth : 0 property int screenHeight : 0 property bool allDesktops: true property string longestCaption: "" property int imagePathPrefix: (new Date()).getTime() property int optimalWidth: listView.maxRowWidth - property int optimalHeight: listView.rowHeight * listView.count + background.margins.top + background.margins.bottom + property int optimalHeight: listView.rowHeight * listView.count + background.topMargin + background.bottomMargin property bool canStretchX: true property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.2, optimalWidth), screenWidth * 0.8) height: Math.min(Math.max(screenHeight * 0.2, optimalHeight), screenHeight * 0.8) focus: true property int textMargin: 2 onLongestCaptionChanged: { listView.maxRowWidth = listView.calculateMaxRowWidth(); } function setModel(model) { listView.model = model; listView.maxRowWidth = listView.calculateMaxRowWidth(); listView.imageId++; } function modelChanged() { listView.imageId++; } /** * Returns the caption with adjustments for minimized items. * @param caption the original caption * @param mimized whether the item is minimized * @return Caption adjusted for minimized state **/ function itemCaption(caption, minimized) { var text = caption; if (minimized) { text = "(" + text + ")"; } return text; } PlasmaCore.Theme { id: theme } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } // delegate Component { id: listDelegate Item { id: delegateItem width: listView.width height: listView.rowHeight Image { id: iconItem source: "image://client/" + index + "/" + informativeTabBox.imagePathPrefix + "-" + listView.imageId + (index == listView.currentIndex ? "/selected" : "/disabled") width: 32 height: 32 sourceSize { width: 32 height: 32 } anchors { verticalCenter: parent.verticalCenter left: parent.left leftMargin: hoverItem.margins.left } } Text { id: captionItem horizontalAlignment: Text.AlignHCenter text: itemCaption(caption, minimized) font.bold: true font.italic: minimized color: theme.textColor elide: Text.ElideMiddle anchors { left: iconItem.right right: parent.right top: parent.top topMargin: informativeTabBox.textMargin + hoverItem.margins.top rightMargin: hoverItem.margins.right } } Text { id: desktopNameItem horizontalAlignment: Text.AlignHCenter text: desktopName font.bold: false font.italic: true color: theme.textColor elide: Text.ElideMiddle visible: informativeTabBox.allDesktops anchors { left: iconItem.right right: parent.right top: captionItem.bottom topMargin: informativeTabBox.textMargin bottom: parent.bottom bottomMargin: informativeTabBox.textMargin + hoverItem.margins.bottom rightMargin: hoverItem.margins.right } } MouseArea { anchors.fill: parent onClicked: { listView.currentIndex = index; listView.currentIndexChanged(listView.currentIndex); } } } } ListView { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "' + itemCaption(informativeTabBox.longestCaption, true) + '"\n' + ' font.bold: true\n' + ' visible: false\n' + '}', listView, "calculateMaxRowWidth"); width = Math.max(textElement.width, width); textElement.destroy(); - return width + 32 + hoverItem.margins.right + hoverItem.margins.left + background.margins.left + background.margins.right; + return width + 32 + hoverItem.margins.right + hoverItem.margins.left + background.leftMargin + background.right;Margin } /** * Calculates the height of one row based on the text height and icon size. * @return Row height **/ function calcRowHeight() { var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "Some Text"\n' + ' font.bold: true\n' + ' visible: false\n' + '}', listView, "calcRowHeight"); var height = textElement.height; textElement.destroy(); // icon size or two text elements and margins and hoverItem margins return Math.max(32, height*2 + informativeTabBox.textMargin * 3 + hoverItem.margins.top + hoverItem.margins.bottom); } signal currentIndexChanged(int index) id: listView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background property int maxRowWidth: calculateMaxRowWidth() property int rowHeight: calcRowHeight() // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 anchors { fill: parent - topMargin: background.margins.top - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + topMargin: background.topMargin + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } clip: true delegate: listDelegate highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: listView.width } highlightMoveDuration: 250 boundsBehavior: Flickable.StopAtBounds } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Up) { listView.decrementCurrentIndex(); listView.currentIndexChanged(listView.currentIndex); } else if (event.key == Qt.Key_Down) { listView.incrementCurrentIndex(); listView.currentIndexChanged(listView.currentIndex); } } } diff --git a/tabbox/qml/clients/present_windows/contents/ui/main.qml b/tabbox/qml/clients/present_windows/contents/ui/main.qml index 14a54d3ab..e539c8970 100644 --- a/tabbox/qml/clients/present_windows/contents/ui/main.qml +++ b/tabbox/qml/clients/present_windows/contents/ui/main.qml @@ -1,195 +1,199 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2012 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.1 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 import org.kde.kwin 0.1 as KWin Item { id: presentWindowsTabBox property int screenWidth : 1 property int screenHeight : 1 property int optimalWidth: 0.9*screenWidth property int optimalHeight: 0.9*screenHeight property int imagePathPrefix: (new Date()).getTime() property int standardMargin: 2 + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: optimalWidth height: optimalHeight focus: true function setModel(model) { thumbnailListView.model = model; thumbnailListView.imageId++; } function modelChanged() { thumbnailListView.imageId++; } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } PlasmaCore.Theme { id: theme } GridView { signal currentIndexChanged(int index) // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 property int rows: Math.round(Math.sqrt(count)) property int columns: (rows*rows < count) ? rows + 1 : rows id: thumbnailListView objectName: "listView" cellWidth: Math.floor(width / columns) cellHeight: Math.floor(height / rows) clip: true anchors { fill: parent - leftMargin: background.margins.left - rightMargin: background.margins.right - topMargin: background.margins.top - bottomMargin: background.margins.bottom + leftMargin: background.leftMargin + rightMargin: background.rightMargin + topMargin: background.topMargin + bottomMargin: background.bottomMargin } delegate: Item { width: thumbnailListView.cellWidth height: thumbnailListView.cellHeight KWin.ThumbnailItem { id: thumbnailItem wId: windowId anchors { top: parent.top left: parent.left right: parent.right bottom: captionItem.top leftMargin: hoverItem.margins.left rightMargin: hoverItem.margins.right topMargin: hoverItem.margins.top bottomMargin: standardMargin } } Item { id: captionItem height: childrenRect.height anchors { left: parent.left right: parent.right bottom: parent.bottom leftMargin: hoverItem.margins.left + standardMargin bottomMargin: hoverItem.margins.bottom rightMargin: hoverItem.margins.right } Image { id: iconItem source: "image://client/" + index + "/" + presentWindowsTabBox.imagePathPrefix + "-" + thumbnailListView.imageId width: 32 height: 32 sourceSize { width: 32 height: 32 } anchors { bottom: parent.bottom right: textItem.left } } Item { id: textItem property int maxWidth: parent.width - iconItem.width - parent.anchors.leftMargin - parent.anchors.rightMargin - anchors.leftMargin - standardMargin * 2 width: (textElementSelected.implicitWidth >= maxWidth) ? maxWidth : textElementSelected.implicitWidth anchors { top: parent.top bottom: parent.bottom horizontalCenter: parent.horizontalCenter leftMargin: standardMargin } Text { id: textElementSelected horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: caption font.italic: minimized font.bold: true visible: index == thumbnailListView.currentIndex color: theme.textColor elide: Text.ElideMiddle anchors.fill: parent } Text { id: textElementNormal horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: caption font.italic: minimized visible: index != thumbnailListView.currentIndex color: theme.textColor elide: Text.ElideMiddle anchors.fill: parent } } } MouseArea { anchors.fill: parent onClicked: { thumbnailListView.currentIndex = index; thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } } } highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: thumbnailListView.cellWidth height: thumbnailListView.cellHeight } boundsBehavior: Flickable.StopAtBounds } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Left) { thumbnailListView.moveCurrentIndexLeft(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } else if (event.key == Qt.Key_Right) { thumbnailListView.moveCurrentIndexRight(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } else if (event.key == Qt.Key_Up) { thumbnailListView.moveCurrentIndexUp(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } else if (event.key == Qt.Key_Down) { thumbnailListView.moveCurrentIndexDown(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } } } diff --git a/tabbox/qml/clients/small_icons/contents/ui/main.qml b/tabbox/qml/clients/small_icons/contents/ui/main.qml index ea09ed0df..0c9b4f7f7 100644 --- a/tabbox/qml/clients/small_icons/contents/ui/main.qml +++ b/tabbox/qml/clients/small_icons/contents/ui/main.qml @@ -1,93 +1,96 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: smallIconsTabBox property int screenWidth : 0 property int screenHeight : 0 property int imagePathPrefix: (new Date()).getTime() - property int optimalWidth: (icons.iconSize + icons.margins.left + icons.margins.right) * icons.count + background.margins.left + background.margins.bottom - property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.margins.top + background.margins.bottom + 40 + property int optimalWidth: (icons.iconSize + icons.margins.left + icons.margins.right) * icons.count + background.leftMargin + background.bottomMargin + property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.topMargin + background.bottomMargin + 40 property bool canStretchX: false property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.1, optimalWidth), screenWidth * 0.9) height: Math.min(Math.max(screenHeight * 0.05, optimalHeight), screenHeight * 0.5) function setModel(model) { icons.setModel(model); } function modelChanged() { icons.modelChanged(); } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } IconTabBox { id: icons iconSize: 16 - height: iconSize + background.margins.top + background.margins.bottom + height: iconSize + background.topMargin + icons.margins.top + icons.margins.bottom anchors { top: parent.top left: parent.left right: parent.right - topMargin: background.margins.top - rightMargin: background.margins.right - bottomMargin: background.margins.bottom - leftMargin: background.margins.left + topMargin: background.topMargin + rightMargin: background.rightMargin + leftMargin: background.leftMargin } } Item { anchors { top: icons.bottom left: parent.left right: parent.right bottom: parent.bottom - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } Text { id: textItem text: icons.currentItem ? icons.currentItem.data.caption : "" + height: paintedHeight horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: theme.textColor elide: Text.ElideMiddle font { bold: true } anchors { right: parent.right left: parent.left verticalCenter: parent.verticalCenter - horizontalCenter: parent.horizontalCenter } } } } diff --git a/tabbox/qml/clients/text/contents/ui/main.qml b/tabbox/qml/clients/text/contents/ui/main.qml index c0def27f3..ccae17d96 100644 --- a/tabbox/qml/clients/text/contents/ui/main.qml +++ b/tabbox/qml/clients/text/contents/ui/main.qml @@ -1,175 +1,179 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 Item { id: textTabBox property int screenWidth : 0 property int screenHeight : 0 property string longestCaption: "" property int optimalWidth: textListView.maxRowWidth - property int optimalHeight: textListView.rowHeight * textListView.count + background.margins.top + background.margins.bottom + property int optimalHeight: textListView.rowHeight * textListView.count + background.topMargin + background.bottomMargin property bool canStretchX: true property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.2, optimalWidth), screenWidth * 0.8) height: Math.min(Math.max(screenHeight * 0.2, optimalHeight), screenHeight * 0.8) focus: true property int textMargin: 2 onLongestCaptionChanged: { textListView.maxRowWidth = textListView.calculateMaxRowWidth(); } function setModel(model) { textListView.model = model; textListView.maxRowWidth = textListView.calculateMaxRowWidth(); textListView.imageId++; } function modelChanged() { textListView.imageId++; } PlasmaCore.Theme { id: theme } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } // delegate Component { id: listDelegate Item { id: delegateItem width: textListView.width height: textListView.rowHeight Text { id: captionItem horizontalAlignment: Text.AlignHCenter text: caption color: theme.textColor elide: Text.ElideMiddle anchors { left: parent.left right: parent.right top: parent.top bottom: parent.bottom topMargin: hoverItem.margins.top rightMargin: hoverItem.margins.right bottomMargin: hoverItem.margins.bottom leftMargin: hoverItem.margins.left } } MouseArea { anchors.fill: parent onClicked: { textListView.currentIndex = index; textListView.currentIndexChanged(textListView.currentIndex); } } } } ListView { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "' + textTabBox.longestCaption + '"\n' + ' visible: false\n' + '}', textListView, "calculateMaxRowWidth"); width = Math.max(textElement.width, width); textElement.destroy(); - return width + hoverItem.margins.right + hoverItem.margins.left + background.margins.left + background.margins.right; + return width + hoverItem.margins.right + hoverItem.margins.left + background.leftMargin + background.right;Margin } /** * Calculates the height of one row based on the text height and icon size. * @return Row height **/ function calcRowHeight() { var textElement = Qt.createQmlObject( 'import Qt 4.7;' + 'Text {\n' + ' text: "Some Text"\n' + ' visible: false\n' + '}', textListView, "calcRowHeight"); var height = textElement.height; textElement.destroy(); // icon size or two text elements and margins and hoverItem margins return height + hoverItem.margins.top + hoverItem.margins.bottom; } signal currentIndexChanged(int index) id: textListView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background property int maxRowWidth: calculateMaxRowWidth() property int rowHeight: calcRowHeight() // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 anchors { fill: parent - topMargin: background.margins.top - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + topMargin: background.topMargin + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } clip: true delegate: listDelegate highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: textListView.width } highlightMoveDuration: 250 boundsBehavior: Flickable.StopAtBounds } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Up) { textListView.decrementCurrentIndex(); textListView.currentIndexChanged(textListView.currentIndex); } else if (event.key == Qt.Key_Down) { textListView.incrementCurrentIndex(); textListView.currentIndexChanged(textListView.currentIndex); } } } diff --git a/tabbox/qml/clients/thumbnails/contents/ui/main.qml b/tabbox/qml/clients/thumbnails/contents/ui/main.qml index efe3ebed6..4c33703d5 100644 --- a/tabbox/qml/clients/thumbnails/contents/ui/main.qml +++ b/tabbox/qml/clients/thumbnails/contents/ui/main.qml @@ -1,200 +1,204 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.qtextracomponents 0.1 import org.kde.kwin 0.1 as KWin Item { id: thumbnailTabBox property int screenWidth : 1 property int screenHeight : 1 property real screenFactor: screenWidth/screenHeight property int imagePathPrefix: (new Date()).getTime() - property int optimalWidth: (thumbnailListView.thumbnailWidth + hoverItem.margins.left + hoverItem.margins.right) * thumbnailListView.count + background.margins.left + background.margins.bottom - property int optimalHeight: thumbnailListView.thumbnailWidth*(1.0/screenFactor) + hoverItem.margins.top + hoverItem.margins.bottom + background.margins.top + background.margins.bottom + 40 + property int optimalWidth: (thumbnailListView.thumbnailWidth + hoverItem.margins.left + hoverItem.margins.right) * thumbnailListView.count + background.leftMargin + background.bottomMargin + property int optimalHeight: thumbnailListView.thumbnailWidth*(1.0/screenFactor) + hoverItem.margins.top + hoverItem.margins.bottom + background.topMargin + background.bottomMargin + 40 property bool canStretchX: false property bool canStretchY: false + property string maskImagePath: "dialogs/background" + property double maskWidth: background.centerWidth + property double maskHeight: background.centerHeight + property int maskTopMargin: background.centerTopMargin + property int maskLeftMargin: background.centerLeftMargin width: Math.min(Math.max(screenWidth * 0.3, optimalWidth), screenWidth * 0.9) height: Math.min(Math.max(screenHeight * 0.15, optimalHeight), screenHeight * 0.7) clip: true focus: true function setModel(model) { thumbnailListView.model = model; thumbnailListView.imageId++; } function modelChanged() { thumbnailListView.imageId++; } - PlasmaCore.FrameSvgItem { + ShadowedSvgItem { id: background anchors.fill: parent - imagePath: "dialogs/background" } // just to get the margin sizes PlasmaCore.FrameSvgItem { id: hoverItem imagePath: "widgets/viewitem" prefix: "hover" visible: false } PlasmaCore.Theme { id: theme } ListView { signal currentIndexChanged(int index) id: thumbnailListView objectName: "listView" orientation: ListView.Horizontal // used for image provider URL to trick Qt into reloading icons when the model changes property int imageId: 0 property int thumbnailWidth: 300 height: thumbnailWidth * (1.0/screenFactor) + hoverItem.margins.bottom + hoverItem.margins.top spacing: 5 highlightMoveDuration: 250 width: Math.min(parent.width - (anchors.leftMargin + anchors.rightMargin) - (hoverItem.margins.left + hoverItem.margins.right), thumbnailWidth * count + 5 * (count - 1)) anchors { top: parent.top - topMargin: background.margins.top - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + topMargin: background.topMargin + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin horizontalCenter: parent.horizontalCenter } clip: true delegate: Item { property alias data: thumbnailItem.data id: delegateItem width: thumbnailListView.thumbnailWidth height: thumbnailListView.thumbnailWidth*(1.0/screenFactor) KWin.ThumbnailItem { property variant data: model id: thumbnailItem wId: windowId anchors { fill: parent leftMargin: hoverItem.margins.left rightMargin: hoverItem.margins.right topMargin: hoverItem.margins.top bottomMargin: hoverItem.margins.bottom } } MouseArea { anchors.fill: parent onClicked: { thumbnailListView.currentIndex = index; thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } } } highlight: PlasmaCore.FrameSvgItem { id: highlightItem imagePath: "widgets/viewitem" prefix: "hover" width: thumbnailListView.thumbnailWidth height: thumbnailListView.thumbnailWidth*(1.0/screenFactor) } boundsBehavior: Flickable.StopAtBounds } Item { height: 40 id: captionFrame anchors { top: thumbnailListView.bottom left: parent.left right: parent.right bottom: parent.bottom topMargin: hoverItem.margins.bottom - leftMargin: background.margins.left - rightMargin: background.margins.right - bottomMargin: background.margins.bottom + leftMargin: background.leftMargin + rightMargin: background.rightMargin + bottomMargin: background.bottomMargin } Image { id: iconItem source: "image://client/" + thumbnailListView.currentIndex + "/" + thumbnailTabBox.imagePathPrefix + "-" + thumbnailListView.imageId width: 32 height: 32 sourceSize { width: 32 height: 32 } anchors { verticalCenter: parent.verticalCenter right: textItem.left rightMargin: 4 } } Text { function constrainWidth() { if (textItem.width > textItem.maxWidth && textItem.width > 0 && textItem.maxWidth > 0) { textItem.width = textItem.maxWidth; } else { textItem.width = undefined; } } function calculateMaxWidth() { textItem.maxWidth = thumbnailTabBox.width - captionFrame.anchors.leftMargin - captionFrame.anchors.rightMargin - iconItem.width * 2 - captionFrame.anchors.rightMargin; } id: textItem property int maxWidth: 0 text: thumbnailListView.currentItem ? thumbnailListView.currentItem.data.caption : "" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: theme.textColor elide: Text.ElideMiddle font { bold: true } anchors { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } onTextChanged: textItem.constrainWidth() Component.onCompleted: textItem.calculateMaxWidth() Connections { target: thumbnailTabBox onWidthChanged: { textItem.calculateMaxWidth(); textItem.constrainWidth(); } } } } /* * Key navigation on outer item for two reasons: * @li we have to emit the change signal * @li on multiple invocation it does not work on the list view. Focus seems to be lost. **/ Keys.onPressed: { if (event.key == Qt.Key_Left) { thumbnailListView.decrementCurrentIndex(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } else if (event.key == Qt.Key_Right) { thumbnailListView.incrementCurrentIndex(); thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); } } } diff --git a/tabbox/qml/tabbox.qml b/tabbox/qml/tabbox.qml index 417623192..9fccc0bdf 100644 --- a/tabbox/qml/tabbox.qml +++ b/tabbox/qml/tabbox.qml @@ -1,74 +1,79 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 1.0 Loader { id: loader focus: true property int screenWidth : 0 property int screenHeight : 0 property bool allDesktops: true property string longestCaption: "" + property string maskImagePath: item && item.maskImagePath != undefined ? item.maskImagePath : "" + property double maskWidth: item && item.maskWidth != undefined ? item.maskWidth : 0 + property double maskHeight: item && item.maskHeight != undefined ? item.maskHeight : 0 + property int maskTopMargin: item && item.maskTopMargin != undefined ? item.maskTopMargin : 0 + property int maskLeftMargin: item && item.maskLeftMargin != undefined ? item.maskLeftMargin : 0 onLoaded: { if (item.screenWidth != undefined) { item.screenWidth = screenWidth; } if (item.screenHeight != undefined) { item.screenHeight = screenHeight; } if (item.allDesktops != undefined) { item.allDesktops = allDesktops; } if (item.longestCaption != undefined) { item.longestCaption = longestCaption; } if (item.setModel) { item.setModel(clientModel); } } onScreenWidthChanged: { if (item && item.screenWidth != undefined) { item.screenWidth = screenWidth; } } onScreenHeightChanged: { if (item && item.screenHeight != undefined) { item.screenHeight = screenHeight; } } onAllDesktopsChanged: { if (item && item.allDesktops != undefined) { item.allDesktops= allDesktops; } } onLongestCaptionChanged: { if (item && item.longestCaption != undefined) { item.longestCaption = longestCaption; } } Connections { target: clientModel onModelReset: { if (item && item.modelChanged) { item.modelChanged(); } } } }