mirror of
https://github.com/KDE/latte-dock.git
synced 2025-02-04 13:47:19 +03:00
drop QMultiComboBox for activities selection
--QMultiComboBox couldnt cooperate nicely with the TableView, a different approach is needed. Probably it is easier to just add a text indicator for the selected activities
This commit is contained in:
parent
747fe2fd02
commit
0dfdd75746
@ -23,7 +23,6 @@ set(lattedock-app_SRCS
|
||||
layoutsDelegates/checkboxdelegate.cpp
|
||||
layoutsDelegates/colorcmbboxdelegate.cpp
|
||||
layoutsDelegates/colorcmbboxitemdelegate.cpp
|
||||
layoutsDelegates/QMultiComboBox.cpp
|
||||
layoutsDelegates/activitycmbboxdelegate.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
@ -188,7 +188,7 @@ void LayoutConfigDialog::loadLayouts()
|
||||
QStandardItem *menu = new QStandardItem();
|
||||
menu->setTextAlignment(Qt::AlignCenter);
|
||||
menu->setEditable(false);
|
||||
//menu->setSelectable(false);
|
||||
menu->setSelectable(false);
|
||||
menu->setCheckable(true);
|
||||
menu->setCheckState(layoutSets.showInMenu() ? Qt::Checked : Qt::Unchecked);
|
||||
m_model->setItem(i - 1, 3, menu);
|
||||
|
@ -1,213 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (c) 2012 Richard Steffen and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: rsteffen@messbild.de, rsteffen@uni-bonn.de
|
||||
**
|
||||
** QMultiComboBox is free to use unter the terms of the LGPL 2.1 License in
|
||||
** Free and Commercial Products.
|
||||
****************************************************************************/
|
||||
|
||||
#include "QMultiComboBox.h"
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
|
||||
QMultiComboBox::QMultiComboBox(QWidget *widget ) :
|
||||
QComboBox(widget),
|
||||
popheight_(0),
|
||||
screenbound_(50),
|
||||
popframe_(NULL, Qt::Popup)
|
||||
{
|
||||
|
||||
SetDisplayText("Not Set");
|
||||
|
||||
// setup the popup list
|
||||
vlist_.setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
vlist_.setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
vlist_.clearSelection();
|
||||
popframe_.setLayout(new QVBoxLayout());
|
||||
popframe_.layout()->addWidget(&vlist_);
|
||||
popframe_.layout()->setContentsMargins(0,0,0,0);
|
||||
|
||||
connect(&vlist_, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(scanItemSelect(QListWidgetItem*)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
QMultiComboBox::~QMultiComboBox()
|
||||
{
|
||||
disconnect(&vlist_,0,0,0);
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::SetDisplayText(QString text)
|
||||
{
|
||||
m_DisplayText_ = text;
|
||||
const int textWidth = fontMetrics().width(text);
|
||||
setMinimumWidth(textWidth + 30);
|
||||
updateGeometry();
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
QString QMultiComboBox::GetDisplayText() const
|
||||
{
|
||||
return m_DisplayText_;
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::setPopupHeight(int h)
|
||||
{
|
||||
popheight_ = h;
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QStylePainter painter(this);
|
||||
painter.setPen(palette().color(QPalette::Text));
|
||||
// draw the combobox frame, focusrect and selected etc.
|
||||
QStyleOptionComboBox opt;
|
||||
|
||||
initStyleOption(&opt);
|
||||
opt.currentText = m_DisplayText_;
|
||||
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
|
||||
// draw the icon and text
|
||||
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::showPopup()
|
||||
{
|
||||
|
||||
QRect rec = QRect(geometry());
|
||||
|
||||
//QPoint p = this->mapToGlobal(QPoint(0,rec.height()));
|
||||
//QRect rec2(p , p + QPoint(rec.width(), rec.height()));
|
||||
|
||||
// get the two possible list points and height
|
||||
QRect screen = QApplication::desktop()->screenGeometry(this);
|
||||
QPoint above = this->mapToGlobal(QPoint(0,0));
|
||||
int aboveHeight = above.y() - screen.y();
|
||||
QPoint below = this->mapToGlobal(QPoint(0,rec.height()));
|
||||
int belowHeight = screen.bottom() - below.y();
|
||||
|
||||
// first activate it with height 1px to get all the items initialized
|
||||
QRect rec2;
|
||||
rec2.setTopLeft(below);
|
||||
rec2.setWidth(rec.width());
|
||||
rec.setHeight(1);
|
||||
popframe_.setGeometry(rec2);
|
||||
popframe_.raise();
|
||||
popframe_.show();
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// determine rect
|
||||
int contheight = vlist_.count()*vlist_.sizeHintForRow(0) + 4; // +4 - should be determined by margins?
|
||||
belowHeight = min(abs(belowHeight)-screenbound_, contheight);
|
||||
aboveHeight = min(abs(aboveHeight)-screenbound_, contheight);
|
||||
|
||||
if (popheight_ > 0) // fixed
|
||||
{
|
||||
rec2.setHeight(popheight_);
|
||||
}
|
||||
else // dynamic
|
||||
{
|
||||
// do we use below or above
|
||||
if (belowHeight==contheight || belowHeight>aboveHeight)
|
||||
{
|
||||
rec2.setTopLeft(below);
|
||||
rec2.setHeight(belowHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
rec2.setTopLeft(above - QPoint(0,aboveHeight));
|
||||
rec2.setHeight(aboveHeight);
|
||||
}
|
||||
}
|
||||
|
||||
popframe_.setGeometry(rec2);
|
||||
popframe_.raise();
|
||||
popframe_.show();
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::hidePopup()
|
||||
{
|
||||
popframe_.hide();
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::addItem ( const QString & text, const QVariant & userData)
|
||||
{
|
||||
QListWidgetItem* wi = new QListWidgetItem(text);
|
||||
wi->setFlags(wi->flags() | Qt::ItemIsUserCheckable);
|
||||
if (userData.toBool())
|
||||
wi->setCheckState(Qt::Checked);
|
||||
else
|
||||
wi->setCheckState(Qt::Unchecked);
|
||||
vlist_.addItem(wi);
|
||||
}
|
||||
|
||||
|
||||
int QMultiComboBox::count()
|
||||
{
|
||||
return vlist_.count();
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::setCurrentIndex(int index)
|
||||
{
|
||||
cout << __FUNCTION__ << "DONT USE THIS ................" << endl;
|
||||
}
|
||||
|
||||
|
||||
QString QMultiComboBox::currentText()
|
||||
{
|
||||
return vlist_.currentItem()->text();
|
||||
}
|
||||
|
||||
|
||||
QString QMultiComboBox::itemText(int row)
|
||||
{
|
||||
return vlist_.item(row)->text();
|
||||
}
|
||||
|
||||
|
||||
QVariant QMultiComboBox::itemData(int row)
|
||||
{
|
||||
QListWidgetItem* item = vlist_.item(row);
|
||||
if (item->checkState() == Qt::Checked) return QVariant(true);
|
||||
return QVariant(false);
|
||||
}
|
||||
|
||||
|
||||
void QMultiComboBox::scanItemSelect(QListWidgetItem* item)
|
||||
{
|
||||
|
||||
QList<QListWidgetItem*> list = vlist_.selectedItems();
|
||||
for (int i = 0; i < list.count(); i++)
|
||||
{
|
||||
if (item->checkState() == Qt::Checked)
|
||||
{
|
||||
list[i]->setCheckState(Qt::Checked);
|
||||
}
|
||||
else
|
||||
{
|
||||
list[i]->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
list[i]->setSelected(false);
|
||||
}
|
||||
emit itemChanged();
|
||||
}
|
||||
|
||||
void QMultiComboBox::initStyleOption(QStyleOptionComboBox *option) const
|
||||
{
|
||||
//Initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified widget.
|
||||
//This is a convenience function; the member variables can also be initialized manually.
|
||||
option->initFrom(this);
|
||||
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Richard Steffen and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: rsteffen@messbild.de, rsteffen@uni-bonn.de
|
||||
**
|
||||
** Observe the License Information
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MULTIBOXCOMBO_H__
|
||||
#define __MULTIBOXCOMBO_H__
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QListWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QStylePainter>
|
||||
|
||||
class QMultiComboBox: public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
QMultiComboBox(QWidget *widget = 0);
|
||||
|
||||
virtual ~QMultiComboBox();
|
||||
|
||||
/// the main display text
|
||||
void SetDisplayText(QString text);
|
||||
|
||||
/// get the main display text
|
||||
QString GetDisplayText() const;
|
||||
|
||||
/// add a item to the list
|
||||
void addItem(const QString& text, const QVariant& userData = QVariant());
|
||||
|
||||
/// custom paint
|
||||
virtual void paintEvent(QPaintEvent *e);
|
||||
|
||||
/// set the height of the popup
|
||||
void setPopupHeight(int h);
|
||||
|
||||
/// replace standard QComboBox Popup
|
||||
void showPopup();
|
||||
void hidePopup();
|
||||
|
||||
/// replace neccessary data access
|
||||
int count();
|
||||
void setCurrentIndex(int index);
|
||||
QString currentText();
|
||||
QString itemText(int row);
|
||||
QVariant itemData(int row);
|
||||
|
||||
signals:
|
||||
/// item changed
|
||||
void itemChanged();
|
||||
|
||||
public slots:
|
||||
|
||||
/// react on changes of the item checkbox
|
||||
void scanItemSelect(QListWidgetItem* item);
|
||||
|
||||
/// the init style
|
||||
void initStyleOption(QStyleOptionComboBox *option) const;
|
||||
|
||||
protected:
|
||||
|
||||
/// the height of the popup
|
||||
int popheight_;
|
||||
|
||||
/// lower/upper screen bound
|
||||
int screenbound_;
|
||||
|
||||
/// hold the main display text
|
||||
QString m_DisplayText_;
|
||||
|
||||
/// popup frame
|
||||
QFrame popframe_;
|
||||
|
||||
/// multi selection list in the popup frame
|
||||
QListWidget vlist_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,14 +1,13 @@
|
||||
#include "activitycmbboxdelegate.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include <QModelIndex>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
|
||||
#include "QMultiComboBox.h"
|
||||
|
||||
#include <KActivities/Info>
|
||||
|
||||
ActivityCmbBoxDelegate::ActivityCmbBoxDelegate(QObject *parent, Latte::LayoutManager *manager)
|
||||
@ -20,14 +19,14 @@ ActivityCmbBoxDelegate::ActivityCmbBoxDelegate(QObject *parent, Latte::LayoutMan
|
||||
|
||||
QWidget *ActivityCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QMultiComboBox *editor = new QMultiComboBox(parent);
|
||||
QComboBox *editor = new QComboBox(parent);
|
||||
|
||||
for (unsigned int i = 0; i < m_activities.count(); ++i) {
|
||||
|
||||
KActivities::Info info(m_activities[i]);
|
||||
|
||||
if (info.state() != KActivities::Info::Invalid) {
|
||||
editor->addItem(info.name(), QVariant(m_activities[i]));
|
||||
editor->addItem(QIcon::fromTheme(info.icon()), info.name(), QVariant(m_activities[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,15 +35,23 @@ QWidget *ActivityCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptio
|
||||
|
||||
void ActivityCmbBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
QMultiComboBox *comboBox = static_cast<QMultiComboBox *>(editor);
|
||||
//QComboBox *comboBox = static_cast<QComboBox *>(editor);
|
||||
//QString value = index.model()->data(index, Qt::BackgroundRole).toString();
|
||||
//comboBox->setCurrentIndex(Colors.indexOf(value));
|
||||
}
|
||||
|
||||
void ActivityCmbBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
//QComboBox *comboBox = static_cast<QComboBox *>(editor);
|
||||
//model->setData(index, comboBox->currentText(), Qt::BackgroundRole);
|
||||
QComboBox *comboBox = static_cast<QComboBox *>(editor);
|
||||
|
||||
for (int i = 0; i < comboBox->count(); ++i) {
|
||||
qDebug() << i << ". " << comboBox->itemData(i);
|
||||
}
|
||||
|
||||
bool value = index.model()->data(index, Qt::UserRole).toBool();
|
||||
qDebug() << " model ::: " << value;
|
||||
|
||||
//model->setData(index, comboBox->currentText(), Qt::UserDataRole);
|
||||
}
|
||||
|
||||
void ActivityCmbBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user