Skip to content

Commit efd4f08

Browse files
committed
WIP: Working on proper sizing and layout of the tags display
1 parent 571f7ba commit efd4f08

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

src/gui/EntryPreviewWidget.ui

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>530</width>
10-
<height>257</height>
10+
<height>296</height>
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -260,8 +260,8 @@
260260
<rect>
261261
<x>0</x>
262262
<y>0</y>
263-
<width>157</width>
264-
<height>63</height>
263+
<width>152</width>
264+
<height>57</height>
265265
</rect>
266266
</property>
267267
<layout class="QHBoxLayout" name="horizontalLayout_8">
@@ -481,13 +481,28 @@
481481
</layout>
482482
</item>
483483
<item row="2" column="1" colspan="5">
484-
<widget class="TagsEdit" name="entryTagsList" native="true">
484+
<widget class="TagsEdit" name="entryTagsList">
485+
<property name="maximumSize">
486+
<size>
487+
<width>16777215</width>
488+
<height>80</height>
489+
</size>
490+
</property>
485491
<property name="focusPolicy">
486-
<enum>Qt::ClickFocus</enum>
492+
<enum>Qt::NoFocus</enum>
487493
</property>
488494
<property name="accessibleName">
489495
<string>Tags list</string>
490496
</property>
497+
<property name="frameShape">
498+
<enum>QFrame::NoFrame</enum>
499+
</property>
500+
<property name="lineWidth">
501+
<number>0</number>
502+
</property>
503+
<property name="sizeAdjustPolicy">
504+
<enum>QAbstractScrollArea::AdjustToContents</enum>
505+
</property>
491506
</widget>
492507
</item>
493508
<item row="1" column="5">
@@ -1218,7 +1233,7 @@
12181233
</customwidget>
12191234
<customwidget>
12201235
<class>TagsEdit</class>
1221-
<extends>QWidget</extends>
1236+
<extends>QScrollArea</extends>
12221237
<header>gui/tag/TagsEdit.h</header>
12231238
<container>1</container>
12241239
</customwidget>

src/gui/entry/EditEntryWidgetMain.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
</item>
145145
<item row="5" column="1">
146146
<widget class="TagsEdit" name="tagsList">
147+
<property name="sizePolicy">
148+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
149+
<horstretch>0</horstretch>
150+
<verstretch>0</verstretch>
151+
</sizepolicy>
152+
</property>
147153
<property name="maximumSize">
148154
<size>
149155
<width>16777215</width>

src/gui/tag/TagsEdit.cpp

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ struct TagsEdit::Impl
339339
}
340340

341341
void insertText(const QString& text) {
342-
currentText().insert(cursor, text);
342+
Q_ASSERT(tags.editingIndex() != tags.end());
343+
tags.editingIndex()->text.insert(cursor, text);
343344
moveCursor(cursor + text.size(), false);
344345
}
345346

@@ -368,7 +369,7 @@ struct TagsEdit::Impl
368369
void setCurrentText(const QString& text)
369370
{
370371
Q_ASSERT(tags.editingIndex() != tags.end());
371-
currentText() = text;
372+
tags.editingIndex()->text = text;
372373
moveCursor(currentText().length(), false);
373374
updateDisplayText();
374375
calcRectsAndUpdateScrollRanges();
@@ -391,7 +392,7 @@ struct TagsEdit::Impl
391392
// and ensures Invariant-1.
392393
void editNewTag(const iterator& i)
393394
{
394-
currentText() = currentText().trimmed();
395+
tags.editingIndex()->text = currentText().trimmed();
395396
auto inserted_at = tags.insert(i, Tag());
396397
setEditingIndex(inserted_at);
397398
moveCursor(0, false);
@@ -618,7 +619,6 @@ struct TagsEdit::Impl
618619
int select_start;
619620
int select_size;
620621
bool cross_deleter;
621-
int hscroll{0};
622622
QTextLayout text_layout;
623623

624624
public:
@@ -641,11 +641,8 @@ struct TagsEdit::Impl
641641
const auto r = currentRect();
642642
const auto txt_p = r.topLeft() + QPoint(TAG_INNER.left(), ((r.height() - fontHeight) / 2));
643643

644-
// Nothing to draw. Don't draw anything to avoid adding text margins.
645-
if (!it->isEmpty()) {
646-
// draw not terminated tag
647-
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
648-
}
644+
// draw not terminated tag
645+
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
649646

650647
// draw cursor
651648
if (drawCursor) {
@@ -663,19 +660,8 @@ TagsEdit::TagsEdit(QWidget* parent)
663660
, impl(new Impl(this))
664661
, completer(new QCompleter)
665662
{
666-
QSizePolicy size_policy(QSizePolicy::Ignored, QSizePolicy::Preferred);
667-
size_policy.setHeightForWidth(true);
668-
setSizePolicy(size_policy);
669-
670-
setFocusPolicy(Qt::StrongFocus);
671-
viewport()->setCursor(Qt::IBeamCursor);
672-
setAttribute(Qt::WA_InputMethodEnabled, true);
673-
setMouseTracking(true);
674-
663+
setReadOnly(false);
675664
setupCompleter();
676-
setCursorVisible(hasFocus());
677-
impl->updateDisplayText();
678-
679665
viewport()->setContentsMargins(TAG_H_SPACING, TAG_V_SPACING, TAG_H_SPACING, TAG_V_SPACING);
680666
}
681667

@@ -694,6 +680,7 @@ void TagsEdit::setReadOnly(bool readOnly)
694680
setCursor(Qt::IBeamCursor);
695681
setAttribute(Qt::WA_InputMethodEnabled, true);
696682
}
683+
setMouseTracking(!m_readOnly);
697684
impl->setReadOnly(m_readOnly);
698685
}
699686

@@ -837,24 +824,20 @@ void TagsEdit::mousePressEvent(QMouseEvent* event)
837824
}
838825
}
839826

840-
QSize TagsEdit::sizeHint() const
827+
QSize TagsEdit::viewportSizeHint() const
841828
{
842-
return minimumSizeHint();
829+
return impl->updateTagRenderStates({0, 0, width(), 0}).size();
843830
}
844831

845-
QSize TagsEdit::minimumSizeHint() const
832+
bool TagsEdit::hasHeightForWidth() const
846833
{
847-
ensurePolished();
848-
QFontMetrics fm = fontMetrics();
849-
QRect rect(0, 0, fm.maxWidth() + TAG_CROSS_PADDING + TAG_CROSS_WIDTH, fm.height() + fm.leading());
850-
rect += TAG_INNER + contentsMargins() + viewport()->contentsMargins() + viewportMargins();
851-
return rect.size();
834+
return true;
852835
}
853836

854837
int TagsEdit::heightForWidth(int w) const
855838
{
856839
const auto content_width = w;
857-
QRect contents_rect(0, 0, content_width, 100);
840+
QRect contents_rect(0, 0, content_width, 32);
858841
contents_rect -= contentsMargins() + viewport()->contentsMargins() + viewportMargins();
859842
contents_rect = impl->updateTagRenderStates(contents_rect);
860843
contents_rect += contentsMargins() + viewport()->contentsMargins() + viewportMargins();

src/gui/tag/TagsEdit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class TagsEdit : public QAbstractScrollArea
3737
explicit TagsEdit(QWidget* parent = nullptr);
3838
~TagsEdit() override;
3939

40-
QSize sizeHint() const override;
41-
QSize minimumSizeHint() const override;
40+
bool hasHeightForWidth() const override;
4241
int heightForWidth(int w) const override;
4342

4443
void setReadOnly(bool readOnly);
@@ -60,6 +59,7 @@ class TagsEdit : public QAbstractScrollArea
6059
void keyPressEvent(QKeyEvent* event) override;
6160
void mouseMoveEvent(QMouseEvent* event) override;
6261
void hideEvent(QHideEvent* event) override;
62+
QSize viewportSizeHint() const override;
6363

6464
private:
6565
bool isAcceptableInput(QKeyEvent const* event) const;

0 commit comments

Comments
 (0)