|
From: Tapio V. <aa...@us...> - 2011-01-10 16:48:12
|
Module: editor
Branch: master
Commit: afa1935390e9d52476ec6fa756652674e773d489
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 10 17:55:18 2011 +0200
Floating notes are now made smaller if they wouldn't fit.
---
notegraphwidget.cc | 22 +++++++++++++++++-----
notelabel.cc | 3 ++-
notelabel.hh | 1 +
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index f5f71b1..5f33ee8 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -93,20 +93,32 @@ void NoteGraphWidget::updateNotes()
// Fixed note encountered, handle the gap (divide notes evenly into it)
if (!gap.isEmpty()) {
gap.end = child->x();
+ int x = gap.begin;
if (gap.width() >= gap.notesWidth()) {
- // We have enough space - no resizing needed
+ // Plenty of space - no resizing needed
int step = (gap.width() - gap.notesWidth()) / (gap.notes.size() + 1);
- int x = gap.begin + step;
+ x += step;
for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
(*it2)->move(x, (*it2)->y());
x += step + (*it2)->width();
}
} else if (gap.width() <= gap.minWidth()) {
// We are at minimum width, enforce it
- // TODO
+ for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
+ (*it2)->move(x, (*it2)->y());
+ (*it2)->resize(NoteLabel::min_width, (*it2)->height());
+ x += NoteLabel::min_width;
+ }
+ // TODO: Doesn't work properly
+ child->move(gap.begin + gap.minWidth(), child->y());
} else {
- // We can fit everything, if we make the notes smaller
- // TODO
+ // Make the notes smaller so that they fit
+ float sf = gap.width() / float(gap.notesWidth());
+ for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
+ (*it2)->move(x, (*it2)->y());
+ (*it2)->resize((*it2)->width() * sf, (*it2)->height());
+ x += (*it2)->width();
+ }
}
}
// Start a new gap
diff --git a/notelabel.cc b/notelabel.cc
index 35bf489..75f3fad 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -8,6 +8,7 @@ namespace {
const int NoteLabel::resize_margin = 5; // How many pixels is the resize area
const int NoteLabel::min_width = 10; // How many pixels is the resize area
+const int NoteLabel::default_size = 50; // The preferred size of notes
NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, const QSize &size, bool floating)
: QLabel(parent), m_labelText(text), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
@@ -26,7 +27,7 @@ void NoteLabel::createPixmap(QSize size)
{
QFontMetrics metric(font());
if (size.width() <= 0) {
- size.rwidth() = 50; // FIXME: Size is fixed
+ size.rwidth() = default_size;
}
if (size.height() <= 0) {
size.rheight() = metric.size(Qt::TextSingleLine, m_labelText).height() + text_margin;
diff --git a/notelabel.hh b/notelabel.hh
index d1a8e8b..1ea91bd 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -7,6 +7,7 @@ class NoteLabel: public QLabel
public:
static const int resize_margin;
static const int min_width;
+ static const int default_size;
NoteLabel(const QString &text, QWidget *parent, const QPoint &position = QPoint(), const QSize &size = QSize(), bool floating = true);
|