This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge branch 'master' of github.com:Razor-qt/razor-qt

  • Loading branch information...
surlykke committed Mar 25, 2013
2 parents 1d75cff + da51285 commit 64c32a930142b7794863f9f708ffd84b5945ee8a
@@ -34,6 +34,7 @@
class RazorGridLayoutPrivate
{
public:
+ RazorGridLayoutPrivate();
QList<QLayoutItem*> mItems;
int mRowCount;
@@ -50,9 +51,27 @@ class RazorGridLayoutPrivate
void updateCache();
int rows() const;
int cols() const;
+ QSize mPrefCellMinSize;
+ QSize mPrefCellMaxSize;
};
+/************************************************
+
+ ************************************************/
+RazorGridLayoutPrivate::RazorGridLayoutPrivate()
+{
+ mColumnCount = 0;
+ mRowCount = 0;
+ mDirection = RazorGridLayout::LeftToRight;
+ mIsValid = false;
+ mVisibleCount = 0;
+ mStretch = RazorGridLayout::StretchHoriz | RazorGridLayout::StretchVert;
+ mPrefCellMinSize = QSize(0,0);
+ mPrefCellMaxSize = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+}
+
+
/************************************************
************************************************/
@@ -96,6 +115,8 @@ void RazorGridLayoutPrivate::updateCache()
#endif
}
+ mCellSizeHint.rwidth() = qBound(mPrefCellMinSize.width(), mCellSizeHint.width(), mPrefCellMaxSize.width());
+ mCellSizeHint.rheight()= qBound(mPrefCellMinSize.height(), mCellSizeHint.height(), mPrefCellMaxSize.height());
mIsValid = !mCellSizeHint.isEmpty();
}
@@ -139,13 +160,6 @@ RazorGridLayout::RazorGridLayout(QWidget *parent):
QLayout(parent),
d_ptr(new RazorGridLayoutPrivate())
{
- Q_D(RazorGridLayout);
- d->mColumnCount = 0;
- d->mRowCount = 0;
- d->mDirection = LeftToRight;
- d->mIsValid = false;
- d->mVisibleCount = 0;
- d->mStretch = StretchHoriz | StretchVert;
}
@@ -320,6 +334,158 @@ void RazorGridLayout::moveItem(int from, int to)
}
+/************************************************
+
+ ************************************************/
+QSize RazorGridLayout::cellMinimumSize() const
+{
+ Q_D(const RazorGridLayout);
+ return d->mPrefCellMinSize;
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMinimumSize(QSize minSize)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize != minSize)
+ {
+ d->mPrefCellMinSize = minSize;
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMinimumHeight(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize.height() != value)
+ {
+ d->mPrefCellMinSize.setHeight(value);
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMinimumWidth(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize.width() != value)
+ {
+ d->mPrefCellMinSize.setWidth(value);
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+QSize RazorGridLayout::cellMaximumSize() const
+{
+ Q_D(const RazorGridLayout);
+ return d->mPrefCellMaxSize;
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMaximumSize(QSize maxSize)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMaxSize != maxSize)
+ {
+ d->mPrefCellMaxSize = maxSize;
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMaximumHeight(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMaxSize.height() != value)
+ {
+ d->mPrefCellMaxSize.setHeight(value);
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellMaximumWidth(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMaxSize.width() != value)
+ {
+ d->mPrefCellMaxSize.setWidth(value);
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellFixedSize(QSize size)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize != size ||
+ d->mPrefCellMaxSize != size)
+ {
+ d->mPrefCellMinSize = size;
+ d->mPrefCellMaxSize = size;
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellFixedHeight(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize.height() != value ||
+ d->mPrefCellMaxSize.height() != value)
+ {
+ d->mPrefCellMinSize.setHeight(value);
+ d->mPrefCellMaxSize.setHeight(value);
+ invalidate();
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+void RazorGridLayout::setCellFixedWidth(int value)
+{
+ Q_D(RazorGridLayout);
+ if (d->mPrefCellMinSize.width() != value ||
+ d->mPrefCellMaxSize.width() != value)
+ {
+ d->mPrefCellMinSize.setWidth(value);
+ d->mPrefCellMaxSize.setWidth(value);
+ invalidate();
+ }
+}
+
+
/************************************************
************************************************/
@@ -348,34 +514,47 @@ void RazorGridLayout::setGeometry(const QRect &geometry)
int y = geometry.top();
int x = geometry.left();
- // WTF? Sometimes geometry width isn't equal (right - left)
- // So we are using geometry.right()-geometry.left() instead geometry.width()
+ // For historical reasons QRect::right returns left() + width() - 1
+ // and QRect::bottom() returns top() + height() - 1;
+ // So we use left() + height() and top() + height()
+ //
+ // http://qt-project.org/doc/qt-4.8/qrect.html
+
+ int maxX = geometry.left() + geometry.width();
+ int maxY = geometry.top() + geometry.height();
+
int itemWidth;
if (d->mStretch.testFlag(StretchHoriz))
{
- itemWidth = (geometry.right() - geometry.left()) * 1.0 / d->cols();
+ itemWidth = geometry.width() * 1.0 / d->cols();
itemWidth = qMin(itemWidth, d->mCellMaxSize.width());
}
else
{
itemWidth = d->mCellSizeHint.width();
}
+ itemWidth = qBound(d->mPrefCellMinSize.width(), itemWidth, d->mPrefCellMaxSize.width());
+
int itemHeight;
if (d->mStretch.testFlag(StretchVert))
{
- itemHeight = (geometry.bottom() - geometry.top()) * 1.0 / d->rows();
+ itemHeight = geometry.height() * 1.0 / d->rows();
itemHeight = qMin(itemHeight, d->mCellMaxSize.height());
}
else
{
itemHeight = d->mCellSizeHint.height();
}
+ itemHeight = qBound(d->mPrefCellMinSize.height(), itemHeight, d->mPrefCellMaxSize.height());
+
+
#if 0
qDebug() << "** RazorGridLayout::setGeometry *******************************";
- qDebug() << "Geometry" << geometry;
- qDebug() << "CellSize" << d->mCellSizeHint;
+ qDebug() << "Geometry:" << geometry;
+ qDebug() << "CellSize:" << d->mCellSizeHint;
+ qDebug() << "Constraints:" << "min" << d->mPrefCellMinSize << "max" << d->mPrefCellMaxSize;
qDebug() << "Count" << count();
qDebug() << "Cols:" << d->cols() << "(" << d->mColumnCount << ")";
qDebug() << "Rows:" << d->rows() << "(" << d->mRowCount << ")";
@@ -389,8 +568,8 @@ void RazorGridLayout::setGeometry(const QRect &geometry)
{
if (!item->widget() || item->widget()->isHidden())
continue;
-;
- if (x + itemWidth > geometry.right())
+
+ if (x + itemWidth > maxX)
{
x = geometry.left();
if (d->mStretch.testFlag(StretchVert))
@@ -411,7 +590,7 @@ void RazorGridLayout::setGeometry(const QRect &geometry)
if (!item->widget() || item->widget()->isHidden())
continue;
- if (y + itemHeight > geometry.height())
+ if (y + itemHeight > maxY)
{
y = geometry.top();
if (d->mStretch.testFlag(StretchHoriz))
@@ -56,8 +56,9 @@ class RazorGridLayout: public QLayout
*/
enum StretchFlag
{
- StretchHoriz = 1, ///< Justifies items in the available horizontal space
- StretchVert = 2 ///< Justifies items in the available vertical space
+ NoStretch = 0, ///< No justifies items
+ StretchHoriz = 1, ///< Justifies items in the available horizontal space
+ StretchVert = 2 ///< Justifies items in the available vertical space
};
Q_DECLARE_FLAGS(Stretch, StretchFlag)
@@ -152,6 +153,74 @@ class RazorGridLayout: public QLayout
**/
void moveItem(int from, int to);
+ /**
+ Returns the cells' minimum size.
+ By default, this property contains a size with zero width and height.
+ **/
+ QSize cellMinimumSize() const;
+
+ /**
+ Sets the minimum size of all cells to minSize pixels.
+ **/
+ void setCellMinimumSize(QSize minSize);
+
+ /**
+ Sets the minimum height of the cells to value without
+ changing the width. Provided for convenience.
+ **/
+ void setCellMinimumHeight(int value);
+
+ /**
+ Sets the minimum width of the cells to value without
+ changing the heights. Provided for convenience.
+ **/
+ void setCellMinimumWidth(int value);
+
+
+
+ /**
+ Returns the cells' maximum size.
+ By default, this property contains a size with zero width and height.
+ **/
+ QSize cellMaximumSize() const;
+
+ /**
+ Sets the maximum size of all cells to maxSize pixels.
+ **/
+ void setCellMaximumSize(QSize maxSize);
+
+ /**
+ Sets the maximum height of the cells to value without
+ changing the width. Provided for convenience.
+ **/
+ void setCellMaximumHeight(int value);
+
+ /**
+ Sets the maximum width of the cells to value without
+ changing the heights. Provided for convenience.
+ **/
+ void setCellMaximumWidth(int value);
+
+
+
+ /**
+ Sets both the minimum and maximum sizes of the cells to size,
+ thereby preventing it from ever growing or shrinking.
+ **/
+ void setCellFixedSize(QSize size);
+
+ /**
+ Sets both the minimum and maximum height of the cells to value without
+ changing the width. Provided for convenience.
+ **/
+ void setCellFixedHeight(int value);
+
+ /**
+ Sets both the minimum and maximum width of the cells to value without
+ changing the heights. Provided for convenience.
+ **/
+ void setCellFixedWidth(int value);
+
private:
RazorGridLayoutPrivate* const d_ptr;
Q_DECLARE_PRIVATE(RazorGridLayout)
@@ -72,6 +72,8 @@ class Plugin : public QFrame
bool isSeparate() const;
bool isExpandable() const;
+ QWidget *widget() { return mPluginWidget; }
+
// For QSS properties ..................
static QColor moveMarkerColor() { return mMoveMarkerColor; }
static void setMoveMarkerColor(QColor color) { mMoveMarkerColor = color; }
Oops, something went wrong.

0 comments on commit 64c32a9

Please sign in to comment.