Fixed file name display in new file dialog (#1675)

This commit is contained in:
xarkes 2019-07-31 13:21:01 +02:00 committed by GitHub
parent a5dc85c3c5
commit 148c7aa9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 19 deletions

View File

@ -9,10 +9,10 @@
#include <QString> #include <QString>
// Workaround for compile errors on Windows // Workaround for compile errors on Windows
#ifdef _WIN32 #ifdef Q_OS_WIN
#undef min #undef min
#undef max #undef max
#endif //_WIN32 #endif // Q_OS_WIN
// radare2 list iteration macros // radare2 list iteration macros
#define CutterRListForeach(list, it, type, x) \ #define CutterRListForeach(list, it, type, x) \

View File

@ -25,7 +25,7 @@ static QColor getColorFor(int pos)
QColor(231, 76, 60), // Red QColor(231, 76, 60), // Red
QColor(243, 156, 17) // Orange QColor(243, 156, 17) // Orange
}; };
return colors[pos % 6]; return colors[pos % colors.size()];
} }
static QIcon getIconFor(const QString &str, int pos) static QIcon getIconFor(const QString &str, int pos)
@ -43,7 +43,10 @@ static QIcon getIconFor(const QString &str, int pos)
pixPaint.setBrush(getColorFor(pos)); pixPaint.setBrush(getColorFor(pos));
pixPaint.drawEllipse(1, 1, w - 2, h - 2); pixPaint.drawEllipse(1, 1, w - 2, h - 2);
pixPaint.setPen(Qt::white); pixPaint.setPen(Qt::white);
pixPaint.setFont(QFont("Verdana", 24, 1)); QFont font = Config()->getFont();
font.setBold(true);
font.setPointSize(18);
pixPaint.setFont(font);
pixPaint.drawText(0, 0, w, h - 2, Qt::AlignCenter, QString(str).toUpper().mid(0, 2)); pixPaint.drawText(0, 0, w, h - 2, Qt::AlignCenter, QString(str).toUpper().mid(0, 2));
return QIcon(pixmap); return QIcon(pixmap);
} }
@ -87,7 +90,8 @@ void NewFileDialog::on_loadFileButton_clicked()
void NewFileDialog::on_selectFileButton_clicked() void NewFileDialog::on_selectFileButton_clicked()
{ {
QString currentDir = Config()->getRecentFolder(); QString currentDir = Config()->getRecentFolder();
const QString &fileName = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Select file"), currentDir)); const QString &fileName = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this,
tr("Select file"), currentDir));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->newFileEdit->setText(fileName); ui->newFileEdit->setText(fileName);
@ -104,8 +108,8 @@ void NewFileDialog::on_selectProjectsDirButton_clicked()
currentDir = QDir::homePath() + currentDir.mid(1); currentDir = QDir::homePath() + currentDir.mid(1);
} }
const QString &dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, const QString &dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this,
tr("Select project path (dir.projects)"), tr("Select project path (dir.projects)"),
currentDir)); currentDir));
if (dir.isEmpty()) { if (dir.isEmpty()) {
return; return;
@ -271,24 +275,27 @@ bool NewFileDialog::fillRecentFilesList()
QMutableListIterator<QString> it(files); QMutableListIterator<QString> it(files);
int i = 0; int i = 0;
while (it.hasNext()) { while (it.hasNext()) {
const QString &file = QDir::toNativeSeparators(it.next()); // Get the file name
// Get stored files const QString &fullpath = QDir::toNativeSeparators(it.next());
const QString homepath = QDir::homePath();
// Remove all but the file name const QString basename = fullpath.section(QDir::separator(), -1);
const QString name = file.section(QDir::separator(), -1); QString filenameHome = fullpath;
filenameHome.replace(homepath, "~");
filenameHome.replace(basename, "");
filenameHome.chop(1); // Remove last character that will be a path separator
// Get file info // Get file info
QFileInfo info(file); QFileInfo info(fullpath);
if (!info.exists()) { if (!info.exists()) {
it.remove(); it.remove();
} else { } else {
// Format the text and add the item to the file list
const QString text = QString("%1\n%2\nSize: %3").arg(basename, filenameHome,
qhelpers::formatBytecount(info.size()));
QListWidgetItem *item = new QListWidgetItem( QListWidgetItem *item = new QListWidgetItem(
getIconFor(name, i++), getIconFor(basename, i++),
file + "\nCreated: " + info.birthTime().toString() + "\nSize: " + qhelpers::formatBytecount( text
info.size())
); );
//":/img/icons/target.svg"), name ); item->setData(Qt::UserRole, fullpath);
item->setData(Qt::UserRole, file);
ui->recentsListWidget->addItem(item); ui->recentsListWidget->addItem(item);
} }
} }