2017-03-29 10:18:37 +00:00
|
|
|
#include "helpers.h"
|
|
|
|
|
2017-04-05 08:56:59 +00:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QTextEdit>
|
2017-04-18 10:03:47 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QCryptographicHash>
|
2017-04-13 15:04:30 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QString>
|
|
|
|
#include <QAbstractItemView>
|
2017-04-05 08:56:59 +00:00
|
|
|
|
2017-04-13 15:04:30 +00:00
|
|
|
|
|
|
|
static QAbstractItemView::ScrollMode scrollMode()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-04-13 15:04:30 +00:00
|
|
|
const bool use_scrollperpixel = true;
|
|
|
|
return use_scrollperpixel ? QAbstractItemView::ScrollPerPixel : QAbstractItemView::ScrollPerItem;
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-13 15:04:30 +00:00
|
|
|
|
|
|
|
namespace qhelpers
|
|
|
|
{
|
2017-04-09 19:55:06 +00:00
|
|
|
// TODO: wouldn't it be enough to setFont on the QWidget?
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void normalizeFont(QPlainTextEdit *edit)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_LINUX
|
2017-03-29 10:18:37 +00:00
|
|
|
QFont anonFont("Inconsolata", 12);
|
|
|
|
QTextDocument *out_doc = edit->document();
|
|
|
|
out_doc->setDefaultFont(anonFont);
|
2017-04-09 19:55:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void normalizeEditFont(QTextEdit *edit)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_LINUX
|
2017-03-29 10:18:37 +00:00
|
|
|
QFont anonFont("Inconsolata", 12);
|
|
|
|
QTextDocument *out_doc = edit->document();
|
|
|
|
out_doc->setDefaultFont(anonFont);
|
2017-04-09 19:55:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
2017-04-05 08:56:59 +00:00
|
|
|
|
2017-04-18 10:03:47 +00:00
|
|
|
QString uniqueProjectName(const QString &filename)
|
|
|
|
{
|
|
|
|
const QByteArray fullHash(QCryptographicHash::hash(filename.toUtf8(), QCryptographicHash::Sha1));
|
|
|
|
return QFileInfo(filename).fileName() + "_" + fullHash.toHex().left(10);
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:04:30 +00:00
|
|
|
void adjustColumns(QTreeWidget *tw)
|
|
|
|
{
|
|
|
|
int count = tw->columnCount();
|
|
|
|
for (int i = 0; i != count; ++i)
|
|
|
|
{
|
|
|
|
tw->resizeColumnToContents(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendRow(QTreeWidget *tw, const QString &str, const QString &str2,
|
|
|
|
const QString &str3, const QString &str4, const QString &str5)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
|
|
|
// Fill dummy hidden column
|
|
|
|
tempItem->setText(0, "0");
|
|
|
|
tempItem->setText(1, str);
|
|
|
|
if (!str2.isNull())
|
|
|
|
tempItem->setText(2, str2);
|
|
|
|
if (!str3.isNull())
|
|
|
|
tempItem->setText(3, str3);
|
|
|
|
if (!str4.isNull())
|
|
|
|
tempItem->setText(4, str4);
|
|
|
|
if (!str5.isNull())
|
|
|
|
tempItem->setText(5, str5);
|
|
|
|
|
|
|
|
tw->insertTopLevelItem(0, tempItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setVerticalScrollMode(QTreeWidget *tw)
|
|
|
|
{
|
|
|
|
tw->setVerticalScrollMode(scrollMode());
|
|
|
|
}
|
|
|
|
|
2017-04-05 08:56:59 +00:00
|
|
|
} // end namespace
|