Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:Razor-qt/razor-qt
Browse files Browse the repository at this point in the history
  • Loading branch information
surlykke committed Mar 25, 2013
2 parents 1d75cff + da51285 commit 64c32a9
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 101 deletions.
211 changes: 195 additions & 16 deletions libraries/razorqt/razorgridlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class RazorGridLayoutPrivate
{
public:
RazorGridLayoutPrivate();

QList<QLayoutItem*> mItems;
int mRowCount;
Expand All @@ -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);
}


/************************************************
************************************************/
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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();
}
}


/************************************************
************************************************/
Expand Down Expand Up @@ -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 << ")";
Expand All @@ -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))
Expand All @@ -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))
Expand Down
73 changes: 71 additions & 2 deletions libraries/razorqt/razorgridlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions razorqt-panel/panel/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading

0 comments on commit 64c32a9

Please sign in to comment.