Skip to content

Commit

Permalink
WIP: Working on proper sizing and layout of the tags display
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Dec 22, 2024
1 parent 571f7ba commit 9f0dee3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
27 changes: 21 additions & 6 deletions src/gui/EntryPreviewWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>530</width>
<height>257</height>
<height>296</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -260,8 +260,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>157</width>
<height>63</height>
<width>152</width>
<height>57</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
Expand Down Expand Up @@ -481,13 +481,28 @@
</layout>
</item>
<item row="2" column="1" colspan="5">
<widget class="TagsEdit" name="entryTagsList" native="true">
<widget class="TagsEdit" name="entryTagsList">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
<enum>Qt::NoFocus</enum>
</property>
<property name="accessibleName">
<string>Tags list</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="1" column="5">
Expand Down Expand Up @@ -1218,7 +1233,7 @@
</customwidget>
<customwidget>
<class>TagsEdit</class>
<extends>QWidget</extends>
<extends>QScrollArea</extends>
<header>gui/tag/TagsEdit.h</header>
<container>1</container>
</customwidget>
Expand Down
6 changes: 6 additions & 0 deletions src/gui/entry/EditEntryWidgetMain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
</item>
<item row="5" column="1">
<widget class="TagsEdit" name="tagsList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
Expand Down
22 changes: 6 additions & 16 deletions src/gui/tag/TagsEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,7 @@ TagsEdit::TagsEdit(QWidget* parent)
, impl(new Impl(this))
, completer(new QCompleter)
{
QSizePolicy size_policy(QSizePolicy::Ignored, QSizePolicy::Preferred);
size_policy.setHeightForWidth(true);
setSizePolicy(size_policy);

setFocusPolicy(Qt::StrongFocus);
viewport()->setCursor(Qt::IBeamCursor);
setAttribute(Qt::WA_InputMethodEnabled, true);
setReadOnly(false);
setMouseTracking(true);

setupCompleter();
Expand Down Expand Up @@ -837,24 +831,20 @@ void TagsEdit::mousePressEvent(QMouseEvent* event)
}
}

QSize TagsEdit::sizeHint() const
QSize TagsEdit::viewportSizeHint() const
{
return minimumSizeHint();
return impl->updateTagRenderStates({0, 0, width(), 0}).size();
}

QSize TagsEdit::minimumSizeHint() const
bool TagsEdit::hasHeightForWidth() const
{
ensurePolished();
QFontMetrics fm = fontMetrics();
QRect rect(0, 0, fm.maxWidth() + TAG_CROSS_PADDING + TAG_CROSS_WIDTH, fm.height() + fm.leading());
rect += TAG_INNER + contentsMargins() + viewport()->contentsMargins() + viewportMargins();
return rect.size();
return true;
}

int TagsEdit::heightForWidth(int w) const
{
const auto content_width = w;
QRect contents_rect(0, 0, content_width, 100);
QRect contents_rect(0, 0, content_width, 32);
contents_rect -= contentsMargins() + viewport()->contentsMargins() + viewportMargins();
contents_rect = impl->updateTagRenderStates(contents_rect);
contents_rect += contentsMargins() + viewport()->contentsMargins() + viewportMargins();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tag/TagsEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class TagsEdit : public QAbstractScrollArea
explicit TagsEdit(QWidget* parent = nullptr);
~TagsEdit() override;

QSize sizeHint() const override;
QSize minimumSizeHint() const override;
bool hasHeightForWidth() const override;
int heightForWidth(int w) const override;

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

private:
bool isAcceptableInput(QKeyEvent const* event) const;
Expand Down

0 comments on commit 9f0dee3

Please sign in to comment.