Skip to content

Commit

Permalink
github release height
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Feb 16, 2022
1 parent b5492c4 commit 8ced2e4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/github/githubmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@ QVariant GitHubManagerModel::data(const QModelIndex &index, int role) const
}
break;
case Qt::SizeHintRole:
if(index.column() == ModColumn)
return QSize(0, itemHeight_);
if(index.column() == ModColumn){
if(auto height = itemHeights_[index])
return QSize(0, height);
else
return QSize(0, 200);
}
break;
}
return QVariant();
}

void GitHubManagerModel::setItemHeight(int newItemHeight)
void GitHubManagerModel::setItemHeight(const QModelIndex &index, int newItemHeight)
{
itemHeight_ = newItemHeight;
itemHeights_[index] = newItemHeight;
}
4 changes: 2 additions & 2 deletions src/github/githubmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class GitHubManagerModel : public QAbstractListModel
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

void setItemHeight(int newItemHeight);
void setItemHeight(const QModelIndex &index, int newItemHeight);

private:
GitHubManager *manager_;
int itemHeight_ = 100;
QMap<QModelIndex, int> itemHeights_;
};

class GitHubManager : public ExploreManager
Expand Down
5 changes: 2 additions & 3 deletions src/ui/github/githubfilelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ void GitHubFileListWidget::setRelease(GitHubRelease *release)
{
release_= release;
emit releaseChanged();
connect(this, &GitHubFileListWidget::releaseChanged, disconnecter(
connect(release_, &QObject::destroyed, this, [=]{setRelease(nullptr); })));

ui->fileListView->setVisible(release_);
if(!release_) return;
connect(this, &GitHubFileListWidget::releaseChanged, disconnecter(
connect(release_, &QObject::destroyed, this, [=]{setRelease(nullptr); })));

updateFileList();
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/github/githubreleaseitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ GitHubReleaseItemWidget::GitHubReleaseItemWidget(GitHubRepoBrowser *parent, cons
ui->name->setText(info.name());
ui->tagName->setText(info.tagName());
ui->body->setMarkdown(info.body());
setFixedHeight(textEditSize(ui->body, 50, 500) + 40);
ui->createDateTime->setText(tr("Created"));
ui->createDateTime->setDateTime(info.created());
ui->publishDateTime->setText(tr("Published"));
Expand Down
8 changes: 1 addition & 7 deletions src/ui/github/githubreleaseitemwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>413</width>
<height>330</height>
<height>158</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -213,12 +213,6 @@
</item>
<item row="2" column="0">
<widget class="QTextBrowser" name="body">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/github/githubrepobrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ QWidget *GitHubRepoBrowser::getListViewIndexWidget(const QModelIndex &index)
auto release = index.data(Qt::UserRole + 1).value<GitHubRelease*>();
if(release){
auto widget = new GitHubReleaseItemWidget(this, release->info());
manager_->model()->setItemHeight(widget->height());
manager_->model()->setItemHeight(index, widget->height());
return widget;
} else
return nullptr;
Expand Down
14 changes: 14 additions & 0 deletions src/util/funcutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QTreeView>
#include <QDateTime>
#include <QStack>
#include <QTextEdit>

#include "local/localmodpath.h"
#include "local/localfilelinker.h"
Expand Down Expand Up @@ -332,3 +333,16 @@ QString installerSuffix()
//linux is unavailable
return "";
}

int textEditSize(QTextEdit *textEdit, int minHeight, int maxHeight)
{
auto *doc = textEdit->document();
doc->adjustSize();
int height = doc->size().height();
if(height < minHeight)
return minHeight;
else if(height > maxHeight)
return maxHeight;
else
return height;
}
4 changes: 4 additions & 0 deletions src/util/funcutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "curseforge/curseforgemodinfo.h"
#include "modrinth/modrinthmodinfo.h"

class QTextEdit;
class QTextDocument;
class LocalModPath;
class CurseforgeMod;
class ModrinthMod;
Expand Down Expand Up @@ -50,6 +52,8 @@ std::function<void ()> disconnecter(QMetaObject::Connection conn, Args... args)

void tweakWidgetFontPointSize(QWidget *widget, int pointSize);

int textEditSize(QTextEdit *textEdit, int minHeight, int maxHeight);

//murmurhash: https://github.com/aappleby/smhasher
uint32_t filteredMurmurHash2(const QByteArray &bytes);

Expand Down

0 comments on commit 8ced2e4

Please sign in to comment.