mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Add more human readable size
This commit is contained in:
parent
3712cf1529
commit
330e230572
@ -3,6 +3,7 @@
|
|||||||
#include "dialogs/NewFileDialog.h"
|
#include "dialogs/NewFileDialog.h"
|
||||||
#include "dialogs/AboutDialog.h"
|
#include "dialogs/AboutDialog.h"
|
||||||
#include "ui_NewfileDialog.h"
|
#include "ui_NewfileDialog.h"
|
||||||
|
#include "utils/Helpers.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
@ -49,18 +50,6 @@ static QIcon getIconFor(const QString& str, int pos)
|
|||||||
return QIcon(pixmap);
|
return QIcon(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString formatBytecount(const long bytecount)
|
|
||||||
{
|
|
||||||
const int exp = log(bytecount) / log(1000);
|
|
||||||
constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'};
|
|
||||||
|
|
||||||
QString str;
|
|
||||||
QTextStream stream(&str);
|
|
||||||
stream << qSetRealNumberPrecision(3) << bytecount / pow(1000, exp)
|
|
||||||
<< ' ' << suffixes[exp] << 'B';
|
|
||||||
return stream.readAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
NewFileDialog::NewFileDialog(QWidget *parent) :
|
NewFileDialog::NewFileDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::NewFileDialog)
|
ui(new Ui::NewFileDialog)
|
||||||
@ -264,7 +253,7 @@ bool NewFileDialog::fillRecentFilesList()
|
|||||||
{
|
{
|
||||||
QListWidgetItem *item = new QListWidgetItem(
|
QListWidgetItem *item = new QListWidgetItem(
|
||||||
getIconFor(name, i++),
|
getIconFor(name, i++),
|
||||||
file + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size())
|
file + "\nCreated: " + info.created().toString() + "\nSize: " + qhelpers::formatBytecount(info.size())
|
||||||
);
|
);
|
||||||
//":/img/icons/target.svg"), name );
|
//":/img/icons/target.svg"), name );
|
||||||
item->setData(Qt::UserRole, file);
|
item->setData(Qt::UserRole, file);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#include "utils/Helpers.h"
|
#include "utils/Helpers.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QtCore>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -11,6 +13,7 @@
|
|||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QAbstractItemView::ScrollMode scrollMode()
|
static QAbstractItemView::ScrollMode scrollMode()
|
||||||
{
|
{
|
||||||
const bool use_scrollperpixel = true;
|
const bool use_scrollperpixel = true;
|
||||||
@ -20,6 +23,18 @@ static QAbstractItemView::ScrollMode scrollMode()
|
|||||||
|
|
||||||
namespace qhelpers
|
namespace qhelpers
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QString formatBytecount(const long bytecount)
|
||||||
|
{
|
||||||
|
const int exp = log(bytecount) / log(1000);
|
||||||
|
constexpr char suffixes[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E'};
|
||||||
|
|
||||||
|
QString str;
|
||||||
|
QTextStream stream(&str);
|
||||||
|
stream << qSetRealNumberPrecision(3) << bytecount / pow(1000, exp)
|
||||||
|
<< ' ' << suffixes[exp] << 'B';
|
||||||
|
return stream.readAll();
|
||||||
|
}
|
||||||
void adjustColumns(QTreeView *tv, int columnCount, int padding)
|
void adjustColumns(QTreeView *tv, int columnCount, int padding)
|
||||||
{
|
{
|
||||||
for (int i = 0; i != columnCount; ++i)
|
for (int i = 0; i != columnCount; ++i)
|
||||||
|
@ -17,6 +17,7 @@ class QTreeView;
|
|||||||
|
|
||||||
namespace qhelpers
|
namespace qhelpers
|
||||||
{
|
{
|
||||||
|
QString formatBytecount(const long bytecount);
|
||||||
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
||||||
void adjustColumns(QTreeWidget *tw, int padding);
|
void adjustColumns(QTreeWidget *tw, int padding);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Dashboard.h"
|
#include "Dashboard.h"
|
||||||
#include "ui_Dashboard.h"
|
#include "ui_Dashboard.h"
|
||||||
|
#include "utils/Helpers.h"
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ void Dashboard::updateContents()
|
|||||||
this->ui->formatEdit->setText(item["format"].toString());
|
this->ui->formatEdit->setText(item["format"].toString());
|
||||||
this->ui->modeEdit->setText(item["mode"].toString());
|
this->ui->modeEdit->setText(item["mode"].toString());
|
||||||
this->ui->typeEdit->setText(item["type"].toString());
|
this->ui->typeEdit->setText(item["type"].toString());
|
||||||
this->ui->sizeEdit->setText(QString::number(item["size"].toDouble()));
|
this->ui->sizeEdit->setText(qhelpers::formatBytecount(item["size"].toDouble()));
|
||||||
this->ui->fdEdit->setText(QString::number(item["fd"].toDouble()));
|
this->ui->fdEdit->setText(QString::number(item["fd"].toDouble()));
|
||||||
|
|
||||||
this->ui->archEdit->setText(item2["arch"].toString());
|
this->ui->archEdit->setText(item2["arch"].toString());
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "utils/Helpers.h"
|
||||||
#include "ResourcesWidget.h"
|
#include "ResourcesWidget.h"
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ QVariant ResourcesModel::data(const QModelIndex &index, int role) const
|
|||||||
case TYPE:
|
case TYPE:
|
||||||
return res->type;
|
return res->type;
|
||||||
case SIZE:
|
case SIZE:
|
||||||
return res->size;
|
return qhelpers::formatBytecount(res->size);
|
||||||
case LANG:
|
case LANG:
|
||||||
return res->lang;
|
return res->lang;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user