summaryrefslogtreecommitdiff
path: root/src/libs/utils
diff options
context:
space:
mode:
authorChristiaan Janssen <christiaan.janssen@nokia.com>2011-01-18 17:17:17 +0100
committerChristiaan Janssen <christiaan.janssen@nokia.com>2011-01-20 15:11:39 +0100
commitf5039a4a022a31cc4c1330d35350ae39cf11b5dd (patch)
tree896474a7d5413705a93042d8347add6acc939f84 /src/libs/utils
parent6a829f5a8fa272bfb4bef92cf40d6d024756be69 (diff)
downloadqt-creator-f5039a4a022a31cc4c1330d35350ae39cf11b5dd.tar.gz
QmlJsInspector: implemented Property Inspector
Reviewed-by: Kai Koehne
Diffstat (limited to 'src/libs/utils')
-rw-r--r--src/libs/utils/crumblepath.cpp80
-rw-r--r--src/libs/utils/crumblepath.h5
2 files changed, 65 insertions, 20 deletions
diff --git a/src/libs/utils/crumblepath.cpp b/src/libs/utils/crumblepath.cpp
index ea1b20b585..fc938c0c78 100644
--- a/src/libs/utils/crumblepath.cpp
+++ b/src/libs/utils/crumblepath.cpp
@@ -57,6 +57,9 @@ public:
explicit CrumblePathButton(const QString &title, QWidget *parent = 0);
void setSegmentType(int type);
+ void select(bool s);
+ void setData(QVariant data);
+ QVariant data() const;
protected:
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *e);
@@ -70,6 +73,7 @@ private:
private:
bool m_isHovering;
bool m_isPressed;
+ bool m_isSelected;
bool m_isEnd;
QColor m_baseColor;
QImage m_segment;
@@ -79,10 +83,12 @@ private:
QImage m_segmentHover;
QImage m_segmentHoverEnd;
QPoint m_textPos;
+
+ QVariant m_data;
};
CrumblePathButton::CrumblePathButton(const QString &title, QWidget *parent)
- : QPushButton(title, parent), m_isHovering(false), m_isPressed(false), m_isEnd(true)
+ : QPushButton(title, parent), m_isHovering(false), m_isPressed(false), m_isSelected(false), m_isEnd(true)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
setToolTip(title);
@@ -114,7 +120,7 @@ void CrumblePathButton::paintEvent(QPaintEvent *)
}
if (m_isEnd) {
- if (m_isPressed) {
+ if (m_isPressed || m_isSelected) {
Utils::StyleHelper::drawCornerImage(m_segmentSelectedEnd, &p, geom, 2, 0, 2, 0);
} else if (m_isHovering) {
Utils::StyleHelper::drawCornerImage(m_segmentHoverEnd, &p, geom, 2, 0, 2, 0);
@@ -122,7 +128,7 @@ void CrumblePathButton::paintEvent(QPaintEvent *)
Utils::StyleHelper::drawCornerImage(m_segmentEnd, &p, geom, 2, 0, 2, 0);
}
} else {
- if (m_isPressed) {
+ if (m_isPressed || m_isSelected) {
Utils::StyleHelper::drawCornerImage(m_segmentSelected, &p, geom, 2, 0, 12, 0);
} else if (m_isHovering) {
Utils::StyleHelper::drawCornerImage(m_segmentHover, &p, geom, 2, 0, 12, 0);
@@ -175,6 +181,12 @@ void CrumblePathButton::mouseReleaseEvent(QMouseEvent *e)
update();
}
+void CrumblePathButton::select(bool s)
+{
+ m_isSelected = s;
+ update();
+}
+
void CrumblePathButton::setSegmentType(int type)
{
bool useLeftPadding = !(type & FirstSegment);
@@ -182,6 +194,16 @@ void CrumblePathButton::setSegmentType(int type)
m_textPos.setX(useLeftPadding ? 18 : 4);
}
+void CrumblePathButton::setData(QVariant data)
+{
+ m_data = data;
+}
+
+QVariant CrumblePathButton::data() const
+{
+ return m_data;
+}
+
struct CrumblePathPrivate {
explicit CrumblePathPrivate(CrumblePath *q);
@@ -216,12 +238,25 @@ CrumblePath::~CrumblePath()
d->m_buttons.clear();
}
+void CrumblePath::selectIndex(int index)
+{
+ if ((index > -1) && (index < d->m_buttons.length()))
+ d->m_buttons[index]->select(true);
+}
+
+QVariant CrumblePath::dataForIndex(int index) const
+{
+ if ((index > -1) && (index < d->m_buttons.length()))
+ return d->m_buttons[index]->data();
+ return QVariant();
+}
+
void CrumblePath::setBackgroundStyle()
{
d->m_background->setStyleSheet("QWidget { background-color:" + d->m_baseColor.name() + ";}");
}
-void CrumblePath::pushElement(const QString &title)
+void CrumblePath::pushElement(const QString &title, const QVariant data)
{
CrumblePathButton *newButton = new CrumblePathButton(title, this);
newButton->hide();
@@ -237,6 +272,7 @@ void CrumblePath::pushElement(const QString &title)
segType = CrumblePathButton::FirstSegment | CrumblePathButton::LastSegment;
newButton->setSegmentType(segType);
}
+ newButton->setData(data);
d->m_buttons.append(newButton);
resizeButtons();
@@ -272,8 +308,6 @@ void CrumblePath::resizeEvent(QResizeEvent *)
void CrumblePath::resizeButtons()
{
- int buttonMinWidth = 0;
- int buttonMaxWidth = 0;
int totalWidthLeft = width();
if (d->m_buttons.length() >= 1) {
@@ -281,26 +315,34 @@ void CrumblePath::resizeButtons()
d->m_buttons[0]->raise();
// rearrange all items so that the first item is on top (added last).
+
+ // compute relative sizes
+ QList <int> sizes;
+ int totalSize = 0;
for(int i = 0; i < d->m_buttons.length() ; ++i) {
CrumblePathButton *button = d->m_buttons[i];
QFontMetrics fm(button->font());
- buttonMinWidth = ArrowBorderSize + fm.width(button->text()) + ArrowBorderSize * 2 ;
- buttonMaxWidth = (totalWidthLeft + ArrowBorderSize * (d->m_buttons.length() - i)) / (d->m_buttons.length() - i);
-
- if (buttonMinWidth > buttonMaxWidth && i < d->m_buttons.length() - 1) {
- buttonMinWidth = buttonMaxWidth;
- } else if (i > 3 && (i == d->m_buttons.length() - 1)) {
- buttonMinWidth = width() - nextElementPosition.x();
- buttonMaxWidth = buttonMinWidth;
- }
-
- button->setMinimumWidth(buttonMinWidth);
- button->setMaximumWidth(buttonMaxWidth);
+ int originalSize = ArrowBorderSize + fm.width(button->text()) + ArrowBorderSize + 12;
+ sizes << originalSize;
+ totalSize += originalSize - ArrowBorderSize;
+ }
+
+ for (int i = 0; i < d->m_buttons.length() ; ++i) {
+ CrumblePathButton *button = d->m_buttons[i];
+
+ int candidateSize = (sizes[i]*totalWidthLeft)/totalSize;
+ if (candidateSize < ArrowBorderSize)
+ candidateSize = ArrowBorderSize;
+ if (candidateSize > sizes[i]*1.3)
+ candidateSize = sizes[i]*1.3;
+
+
+ button->setMinimumWidth(candidateSize);
+ button->setMaximumWidth(candidateSize);
button->move(nextElementPosition);
nextElementPosition.rx() += button->width() - ArrowBorderSize;
- totalWidthLeft -= button->width();
button->show();
if (i > 0)
diff --git a/src/libs/utils/crumblepath.h b/src/libs/utils/crumblepath.h
index 402a4109ae..62efb158d0 100644
--- a/src/libs/utils/crumblepath.h
+++ b/src/libs/utils/crumblepath.h
@@ -37,6 +37,7 @@
#include "utils_global.h"
#include <QtGui/QWidget>
+#include <QVariant>
QT_FORWARD_DECLARE_CLASS(QResizeEvent)
@@ -50,9 +51,11 @@ class QTCREATOR_UTILS_EXPORT CrumblePath : public QWidget
public:
explicit CrumblePath(QWidget *parent = 0);
~CrumblePath();
+ void selectIndex(int index);
+ QVariant dataForIndex(int index) const;
public slots:
- void pushElement(const QString &title);
+ void pushElement(const QString &title, const QVariant data = QVariant());
void popElement();
void clear();