[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: =?utf-8?Q?Re=3A_Review_Request=3A_LayoutWidget_overhaul_and_some_other?=
From: "Christian Mollekopf" <chrigi_1 () gmx ! ch>
Date: 2008-10-25 12:45:36
Message-ID: 20081025124536.217080 () gmx ! net
[Download RAW message or body]
I attached the diff.
Regards
--
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
["layoutWidgetOvehaul.diff" (application/octet-stream)]
Index: taskgroupitem.cpp
===================================================================
--- taskgroupitem.cpp (Revision 875384)
+++ taskgroupitem.cpp (Arbeitskopie)
@@ -65,7 +65,7 @@
m_parentSplitGroup(0),
m_childSplitGroup(0),
m_splitPosition(0),
- m_fillRows(false)
+ m_forceRows(false)
{
setAcceptDrops(true);
}
@@ -471,9 +471,8 @@
//kDebug();
Q_ASSERT(m_group);
m_layoutWidget = new LayoutWidget(this, m_applet);
- m_layoutWidget->setOrientation(m_applet->formFactor());
m_layoutWidget->setMaximumRows(m_maximumRows);
- m_layoutWidget->setFillRows(m_fillRows);
+ m_layoutWidget->setForceRows(m_forceRows);
m_isCollapsed = false;
@@ -794,16 +793,16 @@
}
}
-bool TaskGroupItem::fillRows()
+bool TaskGroupItem::forceRows()
{
- return m_fillRows;
+ return m_forceRows;
}
-void TaskGroupItem::setFillRows(bool fillRows)
+void TaskGroupItem::setForceRows(bool forceRows)
{
- m_fillRows = fillRows;
+ m_forceRows = forceRows;
if (m_layoutWidget) {
- m_layoutWidget->setFillRows(m_fillRows);
+ m_layoutWidget->setForceRows(m_forceRows);
}
}
#include "taskgroupitem.moc"
Index: taskgroupitem.h
===================================================================
--- taskgroupitem.h (Revision 875384)
+++ taskgroupitem.h (Arbeitskopie)
@@ -74,8 +74,8 @@
//TODO remove and calculate reasonable value in the layout itself
void setMaxRows(int);
- void setFillRows(bool);
- bool fillRows();
+ void setForceRows(bool);
+ bool forceRows();
/*
*Why the split group works.
@@ -160,7 +160,7 @@
int m_lastActivated;
int m_activeTaskIndex;
int m_maximumRows;
- bool m_fillRows;
+ bool m_forceRows;
bool m_isCollapsed;
int m_splitPosition;
TaskGroupItem *m_parentSplitGroup;
Index: layoutwidget.cpp
===================================================================
--- layoutwidget.cpp (Revision 875384)
+++ layoutwidget.cpp (Arbeitskopie)
@@ -28,7 +28,7 @@
m_maxRows(1),
m_applet(applet),
m_layout(0),
- m_fillRows(true)
+ m_forceRows(false)
{
init();
//kDebug();
@@ -42,20 +42,11 @@
//kDebug();
}
-void LayoutWidget::calculatePreferredRowSize()
-{
- if (m_fillRows) {
- m_rowSize = 1;
- } else {
- m_rowSize = 6;//TODO calculate a reasonable default value (depending on the \
Font size or the icon size or something)
- }
-}
void LayoutWidget::init()
{
createLayout();
- setOrientation(Plasma::Horizontal);
- calculatePreferredRowSize();
+ //calculatePreferredRowSize();
}
@@ -63,12 +54,8 @@
{
Q_ASSERT(m_applet);
kDebug();
- if (constraints & Plasma::LocationConstraint) {
- setOrientation(m_applet->formFactor());
- }
if (constraints & Plasma::SizeConstraint) {
- calculatePreferredRowSize();
layoutItems();
}
}
@@ -126,15 +113,6 @@
//kDebug() << "done";
}
-void LayoutWidget::setOrientation(Plasma::FormFactor orientation)
-{
- if (orientation == Plasma::Vertical) {
- m_orientation = Qt::Vertical;
- } else {
- m_orientation = Qt::Horizontal;
- }
-}
-
bool LayoutWidget::insert(int index, AbstractTaskItem* item)
{
// kDebug();
@@ -143,10 +121,10 @@
return false;
}
- if ((index <= numberOfItems()) && (index >= 0)) {
+ if ((index <= m_layout->count()) && (index >= 0)) {
m_itemPositions.insert(index, item);
} else {
- m_itemPositions.insert(numberOfItems(), item);
+ m_itemPositions.insert(m_layout->count(), item);
}
layoutItems();
@@ -198,67 +176,86 @@
return groupSize;
}
-/** width including expanded groups*/
-int LayoutWidget::rowWidth(int groupSize)
+//return maximum colums set by the user unless the setting is to high and the items \
would get unusable +int LayoutWidget::maximumRows()
{
- int columns = m_rowSize;
- if (columns < 1) {
- //kDebug() << "divider columns is 0!!!";
+ int maxRows;
+ if (!m_itemPositions.size()) {
return 1;
}
-
- if (m_itemPositions.count() == 0) {
- return 1;
+ // in this case rows are columns, columns are rows...
+ //TODO basicPreferredSize isn't the optimal source here because it changes \
because of margins probably + QSizeF itemSize = \
m_itemPositions[0]->basicPreferredSize(); + if (m_applet->formFactor() == \
Plasma::Vertical) { + maxRows = qMin(qMax(1, \
int(m_groupItem->geometry().width() / itemSize.width())), m_maxRows); + } else {
+ maxRows = qMin(qMax(1, int(m_groupItem->geometry().height() / \
itemSize.height())), m_maxRows); }
+ kDebug() << "maximum rows: " << maxRows << m_maxRows << \
m_groupItem->geometry().height() << itemSize.height(); + return maxRows;
+}
- QSizeF itemSize = m_itemPositions[0]->basicPreferredSize();
-
- //kDebug() << geometry().height() << int(geometry().height() / 22) << m_maxRows;
- int maxRows;
-
- if(m_fillRows) {
- maxRows = m_maxRows;
+//returns a reasonable amount of columns
+int LayoutWidget::preferredColumns()
+{
+ if (m_forceRows) {
+ m_rowSize = 1;
} else {
- // in this case rows are columns, columns are rows...
+ if (!m_itemPositions.size()) {
+ return 1;
+ }
+ //TODO basicPreferredSize isn't the optimal source here because it changes \
because of margins probably + QSizeF itemSize = \
m_itemPositions[0]->basicPreferredSize(); + kDebug() << itemSize.width() << \
m_groupItem->geometry().width(); if (m_applet->formFactor() == Plasma::Vertical) {
- maxRows = qMin(qMax(1, int(m_groupItem->geometry().width() / \
itemSize.width())), m_maxRows); + m_rowSize = qMax(1, \
int(m_groupItem->geometry().height() / itemSize.height())); } else {
- maxRows = qMin(qMax(1, int(m_groupItem->geometry().height() / \
itemSize.height())), m_maxRows); + m_rowSize = qMax(1, \
int(m_groupItem->geometry().width() / itemSize.width())); }
- }
- //kDebug() << m_layout->geometry() << m_groupItem->geometry();
+ }
+ kDebug() << "preferred columns: " << qMax(1, qMin(m_rowSize, size()));
+ return qMax(1, qMin(m_rowSize, size()));
+}
+// <columns,rows>
+QPair<int, int> LayoutWidget::gridLayout()
+{
+ int groupSize = size();
+ //the basic settings
+ int columns = preferredColumns();
+ int maxRows = maximumRows();
+ //check for adjustments on columns because there isnt room enough yet for all of \
the items
while (ceil(static_cast<float>(groupSize)/static_cast<float>(columns)) > \
maxRows) {
columns++; // more rows needed than allowed so we add some columns instead
}
//kDebug() << "groupWidth" << columns << maxRows << m_maxRows;
- return qMax(1, qMin(columns, groupSize));
+ int rows;
+ if (m_forceRows) {
+ rows = maxRows;
+ } else {
+ rows = ceil(static_cast<float>(groupSize) / static_cast<float>(columns)); \
//actually needed rows + }
+
+ return QPair <int,int> (columns, rows);
}
-
void LayoutWidget::createLayout()
{
- if (m_layout) {
- //m_groupItem->setLayout(0); //this also delets the layout
- m_layout = 0;
- }
m_layout = new QGraphicsGridLayout(m_groupItem);
m_layout->setContentsMargins(0,0,0,0);
m_layout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
m_layout->setMaximumSize(INT_MAX,INT_MAX);
- setOrientation(Plasma::Horizontal);
}
void LayoutWidget::layoutItems()
{
kDebug();
+
+ QPair <int,int> grid = gridLayout();
+ int columns = grid.first;
+ int rows = grid.second;
- int totalSize = size(); //get the size including all expanded groups
- // make sure columns is not 0, as that will crash divisions.
- int columns = qMax(1, rowWidth(totalSize)); //now adjust columns if necessary
- //kDebug() << "totalSize/columns" << totalSize << columns;
- int rows = ceil(static_cast<float>(totalSize)/static_cast<float>(columns)); \
//and calculate the rows (rowWidth already took the maximum rows \
setting into account
- kDebug() << "Laying out with" << columns << rows << totalSize;
+ kDebug() << "Laying out with" << columns << rows;
//kDebug() << "geometry" << m_groupItem->geometry();
int rowHeight = qMax(1, int(m_groupItem->geometry().height() / rows));
//kDebug() << "rowHeight" << rowHeight;
@@ -291,7 +288,7 @@
kDebug() << "group has no valid layout";
continue;
}
- int groupRowWidth = layout->rowWidth(layout->size());
+ int groupRowWidth = layout->numberOfColumns();
if ((columns-col) < groupRowWidth) {//we need to split the group
int splitIndex = columns - col;//number of items in group that \
are on this row @@ -333,7 +330,7 @@
if (m_layout->count() > 0) {
AbstractTaskItem *item = dynamic_cast<AbstractTaskItem \
*>(m_layout->itemAt(0)); Q_ASSERT(item);
- if (orientation() == Qt::Vertical) {
+ if (m_applet->formFactor() == Plasma::Vertical) {
m_layout->setPreferredSize(item->basicPreferredSize().width()*m_layout->rowCount(), \
item->basicPreferredSize().height()*m_layout->columnCount()); } else {
m_layout->setPreferredSize(item->basicPreferredSize().width()*m_layout->columnCount(), \
item->basicPreferredSize().height()*m_layout->rowCount()); @@ -342,7 +339,7 @@
//Empty taskbar, arbitrary small value
} else {
kDebug() << "Empty layout!!!!!!!!!!!!!!!!!!";
- if (orientation() == Qt::Vertical) {
+ if (m_applet->formFactor() == Plasma::Vertical) {
m_layout->setPreferredSize(/*m_layout->preferredSize().width()*/10, 10); \
//since we recreate the layout we don't have the previous values } else {
m_layout->setPreferredSize(10, \
/*m_layout->preferredSize().height()*/10); @@ -352,22 +349,17 @@
emit sizeHintChanged(Qt::PreferredSize);
}
-Qt::Orientation LayoutWidget::orientation()
-{
- return m_orientation;
-}
-
void LayoutWidget::setMaximumRows(int rows)
{
m_maxRows = rows;
}
-void LayoutWidget::setFillRows(bool fillRows)
+void LayoutWidget::setForceRows(bool forceRows)
{
- m_fillRows = fillRows;
+ m_forceRows = forceRows;
}
-int LayoutWidget::insertionIndexAt(const QPointF &pos)//FIXME implement vertical
+int LayoutWidget::insertionIndexAt(const QPointF &pos)
{
int insertIndex = -1;
int row = 0;
@@ -379,33 +371,50 @@
return -1;
} else {
QRectF siblingGeometry;
- for (int i = 0; i < m_layout->rowCount(); i++) {
- siblingGeometry = m_layout->itemAt(i, 0)->geometry();//set geometry of \
single item
- if (pos.y() <= siblingGeometry.bottom()) {
- row = i;
- break;
+
+ //get correct row
+ for (int i = 0; i < numberOfRows(); i++) {
+ if (m_applet->formFactor() == Plasma::Vertical) {
+ siblingGeometry = m_layout->itemAt(0, i)->geometry();//set geometry \
of single item + if (pos.x() <= siblingGeometry.right()) {
+ row = i;
+ break;
+ }
+ } else {
+ siblingGeometry = m_layout->itemAt(i, 0)->geometry();//set geometry \
of single item + if (pos.y() <= siblingGeometry.bottom()) {
+ row = i;
+ break;
+ }
}
}
+ //and column
+ for (int i = 0; i < numberOfColumns(); i++) {
+ if (m_applet->formFactor() == Plasma::Vertical) {
+ siblingGeometry = m_layout->itemAt(i, 0)->geometry();//set geometry \
of single item + qreal vertMiddle = (siblingGeometry.top() + \
siblingGeometry.bottom()) / 2.0; + if (pos.y() < vertMiddle) {
+ col = i;
+ break;
+ }
- for (int i = 0; i < itemsInRow(row); i++) {
- siblingGeometry = m_layout->itemAt(0, i)->geometry();//set geometry of \
single item
- qreal horizMiddle = (siblingGeometry.left() + siblingGeometry.right()) / \
2.0;
- //kDebug() << "pos middle " << pos.x() << horizMiddle;
- if (pos.x() < horizMiddle) {
- col = i;
- break;
- } else if (pos.x() <= siblingGeometry.right()) {
- col = i + 1; //take next item if there is one
- break;
+ } else {
+ siblingGeometry = m_layout->itemAt(0, i)->geometry();//set geometry \
of single item + qreal horizMiddle = (siblingGeometry.left() + \
siblingGeometry.right()) / 2.0; + //kDebug() << "pos middle " << \
pos.x() << horizMiddle; + if (pos.x() < horizMiddle) {
+ col = i;
+ break;
+ }
}
}
-
- //kDebug() << row << col;
}
- insertIndex = row *m_layout->columnCount() + col;
+ //kDebug() << row << col;
- if (insertIndex > numberOfItems()) {
+ insertIndex = row *numberOfColumns() + col;
+
+ if (insertIndex > m_layout->count()) {
insertIndex--;
//kDebug() << "correction";
}
@@ -414,44 +423,21 @@
return insertIndex;
}
-int LayoutWidget::numberOfItems()
-{
- //kDebug() << m_layout->count();
- if (m_hasSpacer) {
- //kDebug() << "spacer";
- return (m_layout->count() - 1); //last item is a Spacer
- }
- return (m_layout->count());
-}
-
int LayoutWidget::numberOfRows()
{
- if (orientation() == Qt::Vertical) {
+ if (m_applet->formFactor() == Plasma::Vertical) {
return m_layout->columnCount();
} else {
return m_layout->rowCount();
}
}
-int LayoutWidget::itemsInRow(int row)
+int LayoutWidget::numberOfColumns()
{
- //kDebug() << m_layout->count();
- if (row * m_rowSize < numberOfItems()) { //we are in a full row
- return m_layout->columnCount();
+ if (m_applet->formFactor() == Plasma::Vertical) {
+ return m_layout->rowCount();
} else {
- int val;
- if (orientation() == Qt::Vertical) {
- val = numberOfItems() % m_layout->rowCount();
- if (!val) {
- val = m_layout->rowCount();
- }
- } else {
- val = numberOfItems() % m_layout->columnCount();
- if (!val) {
- val = m_layout->columnCount();
- }
- }
- return val;
+ return m_layout->columnCount();
}
}
Index: tasks.cpp
===================================================================
--- tasks.cpp (Revision 875384)
+++ tasks.cpp (Arbeitskopie)
@@ -125,7 +125,7 @@
m_groupManager->setGroupingStrategy( \
static_cast<TaskManager::GroupManager::TaskGroupingStrategy>(cg.readEntry("groupingStrategy", \
static_cast<int>(TaskManager::GroupManager::ProgramGrouping)))); \
m_groupManager->setSortingStrategy( \
static_cast<TaskManager::GroupManager::TaskSortingStrategy>(cg.readEntry("sortingStrategy", \
static_cast<int>(TaskManager::GroupManager::AlphaSorting)))); \
m_rootGroupItem->setMaxRows( cg.readEntry("maxRows", 2));
- m_rootGroupItem->setFillRows( cg.readEntry("fillRows", false));
+ m_rootGroupItem->setForceRows( cg.readEntry("forceRows", false));
m_rootGroupItem->expand();
emit settingsChanged();
@@ -385,7 +385,7 @@
m_ui.showOnlyCurrentDesktop->setChecked(m_groupManager->showOnlyCurrentDesktop());
m_ui.showOnlyCurrentScreen->setChecked(m_groupManager->showOnlyCurrentScreen());
m_ui.showOnlyMinimized->setChecked(m_groupManager->showOnlyMinimized());
- m_ui.fillRows->setChecked(m_rootGroupItem->fillRows());
+ m_ui.fillRows->setChecked(m_rootGroupItem->forceRows());
m_ui.groupingStrategy->addItem(i18n("Don't \
group"),QVariant(TaskManager::GroupManager::NoGrouping));
m_ui.groupingStrategy->addItem(i18n("Manually"),QVariant(TaskManager::GroupManager::ManualGrouping));
@@ -471,10 +471,10 @@
changed = true;
}
- if (m_rootGroupItem->fillRows() != m_ui.fillRows->isChecked()) {
- m_rootGroupItem->setFillRows(m_ui.fillRows->isChecked());
+ if (m_rootGroupItem->forceRows() != m_ui.fillRows->isChecked()) {
+ m_rootGroupItem->setForceRows(m_ui.fillRows->isChecked());
KConfigGroup cg = config();
- cg.writeEntry("fillRows", m_rootGroupItem->fillRows());
+ cg.writeEntry("forceRows", m_rootGroupItem->forceRows());
changed = true;
}
Index: layoutwidget.h
===================================================================
--- layoutwidget.h (Revision 875384)
+++ layoutwidget.h (Arbeitskopie)
@@ -33,7 +33,6 @@
class TaskGroupItem;
class AbstractTaskItem;
-//class QList;
using TaskManager::StartupPtr;
using TaskManager::TaskPtr;
@@ -41,7 +40,7 @@
/**
- * A task item for a task which represents a expanded group.
+ * A Layout for the expanded group
*/
class LayoutWidget : public QObject
{
@@ -50,22 +49,26 @@
public:
LayoutWidget(TaskGroupItem * parent, Tasks *applet);
~LayoutWidget();
-
+ /** insert the item on the index in TaskGroupItem::getMemberList */
void addTaskItem(AbstractTaskItem*);
void removeTaskItem(AbstractTaskItem*);
+ /** insert the item on a specific index*/
bool insert(int index, AbstractTaskItem* item);
- void setOrientation(Plasma::FormFactor);
- void setSpacer(bool);
+ /** returns the insert index for a task drop on pos */
int insertionIndexAt(const QPointF &pos);
+ /** set the maximum number of rows */
void setMaximumRows(int);
- void setFillRows(bool);
+ /** force the layout to use maximumRows setting and fill rows before columns */
+ void setForceRows(bool);
- Qt::Orientation orientation();
- /** the calculated width according to groupSize and maxRows*/
- int rowWidth(int groupSize);
/** the size including expanded groups*/
int size();
+
+ /** returns columnCount or rowCount depending on m_applet->formFactor() */
+ int numberOfRows();
+ /** returns columnCount or rowCount depending on m_applet->formFactor()*/
+ int numberOfColumns();
public Q_SLOTS:
void update();
@@ -79,34 +82,37 @@
private:
void init();
- void calculatePreferredRowSize();
+ //void calculatePreferredRowSize();
bool remove(AbstractTaskItem* item);
void adjustStretch();
void updatePreferredSize();
+ /** Populates the actual QGraphicsGridLayout with items*/
void layoutItems();
- int numberOfItems();
- int itemsInRow(int);
- int numberOfRows();
-
+ /** Returns the preferred number of rows based on the user settings but limited \
by calculation to honor AbstractGroupableItem::basicPreferredSize()*/ + int \
maximumRows(); + /** Returns the preferred number of columns calculated on base of \
AbstractGroupableItem::basicPreferredSize()*/ + int preferredColumns();
bool m_hasSpacer;
QGraphicsWidget *m_spacer;
TaskGroupItem *m_groupItem;
QList <AbstractTaskItem*> m_itemPositions;
- Qt::Orientation m_orientation;
+ /** Calculates the number of columns and rows for the layoutItems function and \
returns <columns/rows>*/ + QPair<int, int> gridLayout();
+
/** Limit before row is full, more columns are added if maxRows is exeeded*/
int m_rowSize;
- /** How many rows should be used. -1 for autoexpanding until maxRows*/
+ /** How many rows should be used*/
int m_maxRows;
- bool m_fillRows;
+ bool m_forceRows;
Tasks *m_applet;
-
+ /** Creates and initialises a new QGraphicsGridLayout*/
void createLayout();
QGraphicsGridLayout *m_layout;
};
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic