2009-09-13 11:36:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
// own
|
|
|
|
#include "tabboxview.h"
|
|
|
|
// tabbox
|
|
|
|
#include "clientitemdelegate.h"
|
|
|
|
#include "clientmodel.h"
|
|
|
|
#include "desktopitemdelegate.h"
|
|
|
|
#include "desktopmodel.h"
|
|
|
|
#include "tabboxconfig.h"
|
|
|
|
#include "tabboxhandler.h"
|
|
|
|
|
|
|
|
// Qt
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QPainter>
|
2010-01-03 12:11:25 +00:00
|
|
|
#include <QPropertyAnimation>
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// KDE
|
|
|
|
#include <kephal/screens.h>
|
|
|
|
#include <Plasma/FrameSvg>
|
2010-01-03 12:11:25 +00:00
|
|
|
#include <KDebug>
|
2010-06-03 10:33:52 +00:00
|
|
|
#include <KDE/Plasma/Theme>
|
|
|
|
#include <KDE/Plasma/WindowEffects>
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace TabBox
|
|
|
|
{
|
|
|
|
|
2011-07-09 09:12:00 +00:00
|
|
|
TabBoxView::TabBoxView(ClientModel *clientModel, DesktopModel *desktopModel, QWidget* parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
: QWidget(parent)
|
2011-07-09 09:12:00 +00:00
|
|
|
, m_clientModel(clientModel)
|
|
|
|
, m_desktopModel(desktopModel)
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_previewUpdate(false)
|
|
|
|
{
|
|
|
|
setWindowFlags(Qt::X11BypassWindowManagerHint);
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2009-10-29 17:03:15 +00:00
|
|
|
QPalette pal = palette();
|
|
|
|
pal.setColor(backgroundRole(), Qt::transparent);
|
|
|
|
setPalette(pal);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_delegate = new ClientItemDelegate(this);
|
|
|
|
m_additionalClientDelegate = new ClientItemDelegate(this);
|
|
|
|
m_additionalClientDelegate->setShowSelection(false);
|
|
|
|
m_desktopItemDelegate = new DesktopItemDelegate(this);
|
|
|
|
m_additionalDesktopDelegate = new DesktopItemDelegate(this);
|
|
|
|
m_tableView = new TabBoxMainView(this);
|
|
|
|
m_additionalView = new TabBoxAdditionalView(this);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// FrameSvg
|
2011-01-30 14:34:42 +00:00
|
|
|
m_frame = new Plasma::FrameSvg(this);
|
|
|
|
m_frame->setImagePath("dialogs/background");
|
|
|
|
m_frame->setCacheAllRenderedFrames(true);
|
|
|
|
m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
|
|
|
|
|
|
|
m_selectionFrame = new Plasma::FrameSvg(this);
|
|
|
|
m_selectionFrame->setImagePath("widgets/viewitem");
|
|
|
|
m_selectionFrame->setElementPrefix("hover");
|
|
|
|
m_selectionFrame->setCacheAllRenderedFrames(true);
|
|
|
|
m_selectionFrame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
|
|
|
|
|
|
|
m_animation = new QPropertyAnimation(this, "selectedItem", this);
|
2010-01-27 21:23:42 +00:00
|
|
|
m_animation->setDuration(250);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
2010-01-03 12:11:25 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(tabBox, SIGNAL(configChanged()), this, SLOT(configChanged()));
|
|
|
|
connect(m_animation, SIGNAL(valueChanged(QVariant)), SLOT(update()));
|
|
|
|
connect(m_tableView, SIGNAL(activated(QModelIndex)), SLOT(setCurrentIndex(QModelIndex)));
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxView::~TabBoxView()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
void TabBoxView::paintEvent(QPaintEvent* e)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
// paint the background
|
2011-01-30 14:34:42 +00:00
|
|
|
QPainter painter(this);
|
2009-10-29 17:03:15 +00:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setClipRect(e->rect());
|
2011-01-30 14:34:42 +00:00
|
|
|
m_frame->paintFrame(&painter);
|
2010-01-04 20:17:59 +00:00
|
|
|
// and the selection item
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_previewUpdate) {
|
2010-01-04 22:24:30 +00:00
|
|
|
m_previewUpdate = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
setCurrentIndex(m_tableView->currentIndex());
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_selectionFrame->paintFrame(&painter,
|
|
|
|
m_tableView->geometry().topLeft() + m_selectedItem.topLeft());
|
|
|
|
QWidget::paintEvent(e);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool TabBoxView::event(QEvent* event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Paint) {
|
|
|
|
QPainter p(this);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.fillRect(rect(), Qt::transparent);
|
2010-01-04 20:17:59 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
2010-01-04 20:17:59 +00:00
|
|
|
|
2010-01-04 22:24:30 +00:00
|
|
|
void TabBoxView::resizeEvent(QResizeEvent* event)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
m_frame->resizeFrame(event->size());
|
|
|
|
if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
|
2010-06-03 10:33:52 +00:00
|
|
|
// blur background
|
|
|
|
Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
|
|
|
|
Plasma::WindowEffects::overrideShadow(winId(), true);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-06-03 10:33:52 +00:00
|
|
|
// do not trim to mask with compositing enabled, otherwise shadows are cropped
|
2011-01-30 14:34:42 +00:00
|
|
|
setMask(m_frame->mask());
|
2010-01-04 22:24:30 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
}
|
2010-01-04 22:24:30 +00:00
|
|
|
|
2009-09-13 11:36:45 +00:00
|
|
|
void TabBoxView::updateGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_tableView->model()->columnCount() == 0 || m_tableView->model()->rowCount() == 0)
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
|
|
|
QSize hint = sizeHint();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect screenRect = Kephal::ScreenUtils::screenGeometry(tabBox->activeScreen());
|
2009-09-13 11:36:45 +00:00
|
|
|
int x = screenRect.x() + screenRect.width() * 0.5 - hint.width() * 0.5;
|
|
|
|
int y = screenRect.y() + screenRect.height() * 0.5 - hint.height() * 0.5;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setGeometry(x, y, hint.width(), hint.height());
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
QSize TabBoxView::sizeHint() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_tableView->model()->columnCount() == 0 || m_tableView->model()->rowCount() == 0)
|
|
|
|
return QSize(0, 0);
|
2009-09-13 11:36:45 +00:00
|
|
|
// calculate width and height
|
|
|
|
QSize tabBoxSize = m_tableView->sizeHint();
|
|
|
|
qreal columnWidth = tabBoxSize.width() / m_tableView->model()->columnCount();
|
|
|
|
qreal rowHeight = tabBoxSize.height() / m_tableView->model()->rowCount();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < m_tableView->model()->rowCount(); i++)
|
|
|
|
m_tableView->setRowHeight(i, rowHeight);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// additional view
|
|
|
|
QSize additionalSize = m_additionalView->sizeHint();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < m_additionalView->model()->columnCount(); i++)
|
|
|
|
m_additionalView->setColumnWidth(i, additionalSize.width());
|
|
|
|
for (int i = 0; i < m_additionalView->model()->rowCount(); i++)
|
|
|
|
m_additionalView->setRowHeight(i, additionalSize.height());
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// reserve some space for borders
|
|
|
|
qreal top, bottom, left, right;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_frame->getMargins(left, top, right, bottom);
|
2009-09-13 11:36:45 +00:00
|
|
|
int width = columnWidth * m_tableView->model()->columnCount() + left + right;
|
|
|
|
int height = rowHeight * m_tableView->model()->rowCount() + top + bottom;
|
2010-01-03 14:41:25 +00:00
|
|
|
qreal addedWidth = left + right;
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// depending on layout of additional view we have to add some width or height
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(tabBox->config().selectedItemViewPosition()) {
|
|
|
|
case TabBoxConfig::AbovePosition: // fall through
|
|
|
|
case TabBoxConfig::BelowPosition:
|
|
|
|
if (additionalSize.width() + int(left + right) > width) {
|
|
|
|
addedWidth += (additionalSize.width() + int(left + right) - width);
|
|
|
|
width = additionalSize.width() + int(left + right);
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
height = height + additionalSize.height();
|
|
|
|
break;
|
|
|
|
case TabBoxConfig::LeftPosition: // fall through
|
|
|
|
case TabBoxConfig::RightPosition:
|
|
|
|
width = width + additionalSize.width();
|
|
|
|
addedWidth += additionalSize.width();
|
|
|
|
height = qMax(height, additionalSize.height() + int(top + bottom));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// don't add
|
|
|
|
break;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect screenRect = Kephal::ScreenUtils::screenGeometry(tabBox->activeScreen());
|
|
|
|
width = qBound(screenRect.width() * tabBox->config().minWidth() / 100, width,
|
|
|
|
screenRect.width());
|
|
|
|
height = qBound(screenRect.height() * tabBox->config().minHeight() / 100, height,
|
|
|
|
screenRect.height());
|
|
|
|
if (width - addedWidth > tabBoxSize.width()) {
|
2010-01-03 14:41:25 +00:00
|
|
|
columnWidth = (width - addedWidth) / m_tableView->model()->columnCount();
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_tableView->setMinimumWidth(width - addedWidth);
|
|
|
|
for (int i = 0; i < m_tableView->model()->columnCount(); i++)
|
|
|
|
m_tableView->setColumnWidth(i, columnWidth);
|
|
|
|
return QSize(width, height);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxView::setCurrentIndex(QModelIndex index)
|
|
|
|
{
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_tableView->setCurrentIndex(index);
|
|
|
|
const QRect visualRect = m_tableView->visualRect(index);
|
|
|
|
if (m_selectedItem.isNull())
|
2010-01-04 20:17:59 +00:00
|
|
|
m_selectedItem = visualRect;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation->state() == QPropertyAnimation::Running) {
|
2010-01-04 20:17:59 +00:00
|
|
|
m_animation->stop();
|
|
|
|
m_selectedItem = visualRect;
|
|
|
|
update();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
m_animation->setStartValue(m_selectedItem);
|
|
|
|
m_animation->setEndValue(visualRect);
|
2010-01-03 12:11:25 +00:00
|
|
|
m_animation->start();
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_selectionFrame->resizeFrame(visualRect.size());
|
|
|
|
m_additionalView->setCurrentIndex(index);
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
void TabBoxView::configChanged()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
switch(tabBox->config().tabBoxMode()) {
|
|
|
|
case TabBoxConfig::ClientTabBox:
|
|
|
|
m_tableView->setModel(m_clientModel);
|
|
|
|
m_tableView->setItemDelegate(m_delegate);
|
|
|
|
m_additionalView->setModel(m_clientModel);
|
|
|
|
m_additionalView->setItemDelegate(m_additionalClientDelegate);
|
|
|
|
break;
|
|
|
|
case TabBoxConfig::DesktopTabBox:
|
|
|
|
m_tableView->setModel(m_desktopModel);
|
|
|
|
m_tableView->setItemDelegate(m_desktopItemDelegate);
|
|
|
|
m_additionalView->setModel(m_desktopModel);
|
|
|
|
m_additionalView->setItemDelegate(m_additionalDesktopDelegate);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
QLayout* old = layout();
|
|
|
|
QLayoutItem *child;
|
2011-01-30 14:34:42 +00:00
|
|
|
while (old && (child = old->takeAt(0)) != 0) {
|
2009-09-13 11:36:45 +00:00
|
|
|
delete child;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
delete old;
|
|
|
|
QBoxLayout *layout;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(tabBox->config().selectedItemViewPosition()) {
|
|
|
|
case TabBoxConfig::AbovePosition: {
|
|
|
|
layout = new QVBoxLayout();
|
|
|
|
QHBoxLayout* horizontalLayout1 = new QHBoxLayout();
|
|
|
|
horizontalLayout1->addStretch();
|
|
|
|
horizontalLayout1->addWidget(m_additionalView);
|
|
|
|
horizontalLayout1->addStretch();
|
|
|
|
layout->addLayout(horizontalLayout1);
|
|
|
|
layout->addStretch();
|
|
|
|
QHBoxLayout* horizontalLayout2 = new QHBoxLayout();
|
|
|
|
horizontalLayout2->addStretch();
|
|
|
|
horizontalLayout2->addWidget(m_tableView);
|
|
|
|
horizontalLayout2->addStretch();
|
|
|
|
layout->addLayout(horizontalLayout2);
|
|
|
|
m_additionalView->show();
|
|
|
|
break;
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
case TabBoxConfig::BelowPosition: {
|
|
|
|
layout = new QVBoxLayout();
|
|
|
|
QHBoxLayout* horizontalLayout1 = new QHBoxLayout();
|
|
|
|
horizontalLayout1->addStretch();
|
|
|
|
horizontalLayout1->addWidget(m_tableView);
|
|
|
|
horizontalLayout1->addStretch();
|
|
|
|
layout->addLayout(horizontalLayout1);
|
|
|
|
layout->addStretch();
|
|
|
|
QHBoxLayout* horizontalLayout2 = new QHBoxLayout();
|
|
|
|
horizontalLayout2->addStretch();
|
|
|
|
horizontalLayout2->addWidget(m_additionalView);
|
|
|
|
horizontalLayout2->addStretch();
|
|
|
|
layout->addLayout(horizontalLayout2);
|
|
|
|
m_additionalView->show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TabBoxConfig::LeftPosition: {
|
|
|
|
layout = new QHBoxLayout();
|
|
|
|
QVBoxLayout* verticalLayout1 = new QVBoxLayout();
|
|
|
|
verticalLayout1->addStretch();
|
|
|
|
verticalLayout1->addWidget(m_additionalView);
|
|
|
|
verticalLayout1->addStretch();
|
|
|
|
layout->addLayout(verticalLayout1);
|
|
|
|
layout->addStretch();
|
|
|
|
QVBoxLayout* verticalLayout2 = new QVBoxLayout();
|
|
|
|
verticalLayout2->addStretch();
|
|
|
|
verticalLayout2->addWidget(m_tableView);
|
|
|
|
verticalLayout2->addStretch();
|
|
|
|
layout->addLayout(verticalLayout2);
|
|
|
|
m_additionalView->show();
|
|
|
|
break;
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
case TabBoxConfig::RightPosition: {
|
|
|
|
layout = new QHBoxLayout();
|
|
|
|
QVBoxLayout* verticalLayout1 = new QVBoxLayout();
|
|
|
|
verticalLayout1->addStretch();
|
|
|
|
verticalLayout1->addWidget(m_tableView);
|
|
|
|
verticalLayout1->addStretch();
|
|
|
|
layout->addLayout(verticalLayout1);
|
|
|
|
layout->addStretch();
|
|
|
|
QVBoxLayout* verticalLayout2 = new QVBoxLayout();
|
|
|
|
verticalLayout2->addStretch();
|
|
|
|
verticalLayout2->addWidget(m_additionalView);
|
|
|
|
verticalLayout2->addStretch();
|
|
|
|
layout->addLayout(verticalLayout2);
|
|
|
|
m_additionalView->show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
layout = new QVBoxLayout();
|
|
|
|
layout->addStretch();
|
|
|
|
layout->addWidget(m_tableView);
|
|
|
|
layout->addStretch();
|
|
|
|
m_additionalView->hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setLayout(layout);
|
|
|
|
if (m_preview)
|
|
|
|
m_previewUpdate = true;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex TabBoxView::indexAt(QPoint pos)
|
|
|
|
{
|
|
|
|
return m_tableView->indexAt(m_tableView->mapFromParent(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBoxView::setPreview(bool preview)
|
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
m_preview = preview;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (preview)
|
|
|
|
m_frame->setImagePath("dialogs/opaque/background");
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* TabBoxMainView
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
TabBoxMainView::TabBoxMainView(QWidget* parent)
|
|
|
|
: QTableView(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
viewport()->setAutoFillBackground(false);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// adjust table view to needs of tabbox
|
2011-01-30 14:34:42 +00:00
|
|
|
setShowGrid(false);
|
2009-09-13 11:36:45 +00:00
|
|
|
horizontalHeader()->hide();
|
|
|
|
verticalHeader()->hide();
|
2011-01-30 14:34:42 +00:00
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
setSelectionBehavior(QAbstractItemView::SelectItems);
|
|
|
|
setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
|
|
|
|
setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxMainView::~TabBoxMainView()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
QSize TabBoxMainView::sizeHint() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
int maxWidth = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
int minWidth = sizeHintForColumn(0);
|
2009-09-13 11:36:45 +00:00
|
|
|
int maxHeight = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
int minHeight = sizeHintForRow(0);
|
|
|
|
for (int i = 0; i < model()->columnCount(); i++) {
|
|
|
|
minWidth = qMin(minWidth, sizeHintForColumn(i));
|
|
|
|
maxWidth = qMax(maxWidth, sizeHintForColumn(i));
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < model()->rowCount(); i++) {
|
|
|
|
minHeight = qMin(minHeight, sizeHintForRow(i));
|
|
|
|
maxHeight = qMax(maxHeight, sizeHintForRow(i));
|
|
|
|
}
|
|
|
|
qreal columnWidth = (minWidth + qreal(maxWidth - minWidth) / 2.0);
|
|
|
|
qreal rowHeight = (minHeight + qreal(maxHeight - minHeight) / 2.0);
|
|
|
|
return QSize(columnWidth * model()->columnCount(),
|
|
|
|
rowHeight * model()->rowCount());
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2010-01-04 22:24:30 +00:00
|
|
|
QModelIndex TabBoxMainView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(cursorAction)
|
|
|
|
Q_UNUSED(modifiers)
|
2010-01-04 22:24:30 +00:00
|
|
|
return currentIndex();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-04 22:24:30 +00:00
|
|
|
|
2009-09-13 11:36:45 +00:00
|
|
|
/********************************************************
|
|
|
|
* TabBoxAdditonalView
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
TabBoxAdditionalView::TabBoxAdditionalView(QWidget* parent)
|
|
|
|
: QTableView(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
viewport()->setAutoFillBackground(false);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// adjust table view to needs of tabbox
|
2011-01-30 14:34:42 +00:00
|
|
|
setShowGrid(false);
|
2009-09-13 11:36:45 +00:00
|
|
|
horizontalHeader()->hide();
|
|
|
|
verticalHeader()->hide();
|
2011-01-30 14:34:42 +00:00
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
setSelectionBehavior(QAbstractItemView::SelectItems);
|
|
|
|
setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
|
|
|
|
setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
|
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxAdditionalView::~TabBoxAdditionalView()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
QSize TabBoxAdditionalView::sizeHint() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
int maxWidth = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
int minWidth = sizeHintForColumn(0);
|
2009-09-13 11:36:45 +00:00
|
|
|
int maxHeight = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
int minHeight = sizeHintForRow(0);
|
|
|
|
for (int i = 0; i < model()->columnCount(); i++) {
|
|
|
|
minWidth = qMin(minWidth, sizeHintForColumn(i));
|
|
|
|
maxWidth = qMax(maxWidth, sizeHintForColumn(i));
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < model()->rowCount(); i++) {
|
|
|
|
minHeight = qMin(minHeight, sizeHintForRow(i));
|
|
|
|
maxHeight = qMax(maxHeight, sizeHintForRow(i));
|
|
|
|
}
|
|
|
|
qreal columnWidth = (minWidth + qreal(maxWidth - minWidth) / 2.0);
|
|
|
|
qreal rowHeight = (minHeight + qreal(maxHeight - minHeight) / 2.0);
|
|
|
|
return QSize(columnWidth, rowHeight);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex TabBoxAdditionalView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
|
|
|
{
|
|
|
|
Q_UNUSED(cursorAction)
|
|
|
|
Q_UNUSED(modifiers)
|
2010-01-04 22:24:30 +00:00
|
|
|
return currentIndex();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-04 22:24:30 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxAdditionalView::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
2010-01-04 22:24:30 +00:00
|
|
|
|
2009-09-13 11:36:45 +00:00
|
|
|
} // namespace Tabbox
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#include "tabboxview.moc"
|