all repos — mgba @ 849f80e7a1959923c9d3d47191d0a162f0887bb9

mGBA Game Boy Advance Emulator

Qt: Improve size column display
Vicki Pfau vi@endrift.com
Fri, 27 Jan 2017 16:56:13 -0800
commit

849f80e7a1959923c9d3d47191d0a162f0887bb9

parent

46782f16a06d03de5fc85a15193f2238b9dca661

2 files changed, 18 insertions(+), 3 deletions(-)

jump to
M src/platform/qt/LibraryModel.cppsrc/platform/qt/LibraryModel.cpp

@@ -40,16 +40,17 @@ tr("Size"),

[](const mLibraryEntry& e) -> QString { double size = e.filesize; QString unit = "B"; - if (size > 1024.0) { + if (size >= 1024.0) { size /= 1024.0; unit = "kiB"; } - if (size > 1024.0) { + if (size >= 1024.0) { size /= 1024.0; unit = "MiB"; } return QString("%0 %1").arg(size, 0, 'f', 1).arg(unit); - } + }, + Qt::AlignRight }; s_columns["platform"] = { tr("Platform"),

@@ -174,6 +175,8 @@ case Qt::SizeHintRole: {

QFontMetrics fm((QFont())); return fm.size(Qt::TextSingleLine, m_columns[index.column()].value(entry)); } + case Qt::TextAlignmentRole: + return m_columns[index.column()].alignment; default: return QVariant(); }

@@ -250,6 +253,15 @@ emit doneLoading();

} } +LibraryModel::LibraryColumn::LibraryColumn() { +} + +LibraryModel::LibraryColumn::LibraryColumn(const QString& name, std::function<QString(const mLibraryEntry&)> value, int alignment) + : name(name) + , value(value) + , alignment(alignment) +{ +} LibraryModel::LibraryHandle::LibraryHandle(mLibrary* lib, const QString& p) : library(lib)
M src/platform/qt/LibraryModel.hsrc/platform/qt/LibraryModel.h

@@ -58,8 +58,11 @@ void directoryLoaded(const QString& path);

private: struct LibraryColumn { + LibraryColumn(); + LibraryColumn(const QString&, std::function<QString(const mLibraryEntry&)>, int = Qt::AlignLeft); QString name; std::function<QString(const mLibraryEntry&)> value; + int alignment; }; class LibraryHandle {