Replaced font handling by FontSizeHandler and reenabled deactivated item delegates

This commit is contained in:
thunder2 2025-03-26 01:24:14 +01:00
parent 93154fddc4
commit 973246624f
31 changed files with 196 additions and 383 deletions

View file

@ -230,7 +230,8 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
int ltwH = misc::getFontSizeFactor("LobbyTreeWidget", 1.5).height(); int ltwH = misc::getFontSizeFactor("LobbyTreeWidget", 1.5).height();
ui.lobbyTreeWidget->setIconSize(QSize(ltwH,ltwH)); ui.lobbyTreeWidget->setIconSize(QSize(ltwH,ltwH));
updateFontSize();
mFontSizeHandler.registerFontSize(ui.lobbyTreeWidget);
} }
ChatLobbyWidget::~ChatLobbyWidget() ChatLobbyWidget::~ChatLobbyWidget()
@ -1369,25 +1370,3 @@ int ChatLobbyWidget::getNumColVisible()
} }
return iNumColVis; return iNumColVis;
} }
void ChatLobbyWidget::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void ChatLobbyWidget::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui.lobbyTreeWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui.lobbyTreeWidget->setFont(newFont);
}
}

View file

@ -25,6 +25,7 @@
#include "chat/ChatLobbyUserNotify.h" #include "chat/ChatLobbyUserNotify.h"
#include "gui/gxs/GxsIdChooser.h" #include "gui/gxs/GxsIdChooser.h"
#include "util/FontSizeHandler.h"
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
@ -76,8 +77,6 @@ public:
uint unreadCount(); uint unreadCount();
virtual void showEvent(QShowEvent *) ;
signals: signals:
void unreadCountChanged(uint unreadCount); void unreadCountChanged(uint unreadCount);
@ -114,7 +113,6 @@ private slots:
void updateNotify(ChatLobbyId id, unsigned int count) ; void updateNotify(ChatLobbyId id, unsigned int count) ;
void idChooserCurrentIndexChanged(int index); void idChooserCurrentIndexChanged(int index);
void updateFontSize();
private: private:
void autoSubscribeLobby(QTreeWidgetItem *item); void autoSubscribeLobby(QTreeWidgetItem *item);
@ -149,6 +147,8 @@ private:
QAbstractButton* myInviteYesButton; QAbstractButton* myInviteYesButton;
GxsIdChooser* myInviteIdChooser; GxsIdChooser* myInviteIdChooser;
FontSizeHandler mFontSizeHandler;
/* UI - from Designer */ /* UI - from Designer */
Ui::ChatLobbyWidget ui; Ui::ChatLobbyWidget ui;
}; };

View file

@ -168,8 +168,8 @@ SearchDialog::SearchDialog(QWidget *parent)
// To allow a proper sorting, be careful to pad at right with spaces. This // To allow a proper sorting, be careful to pad at right with spaces. This
// is achieved by using QString("%1").arg(number,15,10). // is achieved by using QString("%1").arg(number,15,10).
// //
//ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, mSizeColumnDelegate=new RSHumanReadableSizeDelegate()) ; ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, mSizeColumnDelegate=new RSHumanReadableSizeDelegate()) ;
//ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, mAgeColumnDelegate=new RSHumanReadableAgeDelegate()) ; ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, mAgeColumnDelegate=new RSHumanReadableAgeDelegate()) ;
/* make it extended selection */ /* make it extended selection */
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection); ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
@ -202,10 +202,6 @@ SearchDialog::SearchDialog(QWidget *parent)
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder); ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
QFontMetricsF fontMetrics(ui.searchResultWidget->font());
int iconHeight = fontMetrics.height() * 1.4;
ui.searchResultWidget->setIconSize(QSize(iconHeight, iconHeight));
/* Set initial size the splitter */ /* Set initial size the splitter */
QList<int> sizes; QList<int> sizes;
sizes << 250 << width(); // Qt calculates the right sizes sizes << 250 << width(); // Qt calculates the right sizes
@ -240,6 +236,8 @@ SearchDialog::SearchDialog(QWidget *parent)
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
}, mEventHandlerId, RsEventType::FILE_TRANSFER ); }, mEventHandlerId, RsEventType::FILE_TRANSFER );
mFontSizeHandler.registerFontSize(ui.searchSummaryWidget);
mFontSizeHandler.registerFontSize(ui.searchResultWidget, 1.4f);
} }
SearchDialog::~SearchDialog() SearchDialog::~SearchDialog()
@ -256,8 +254,8 @@ SearchDialog::~SearchDialog()
delete mSizeColumnDelegate; delete mSizeColumnDelegate;
delete mAgeColumnDelegate; delete mAgeColumnDelegate;
//ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, nullptr); ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, nullptr);
//ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, nullptr); ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, nullptr);
rsEvents->unregisterEventsHandler(mEventHandlerId); rsEvents->unregisterEventsHandler(mEventHandlerId);
} }
@ -1042,7 +1040,7 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setText(SR_SOURCES_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_SOURCES_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight | Qt::AlignVCenter );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
setIconAndType(child, QString::fromUtf8(dir.name.c_str())); setIconAndType(child, QString::fromUtf8(dir.name.c_str()));
@ -1067,7 +1065,7 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_SOURCES_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_SOURCES_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight | Qt::AlignVCenter );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
child->setText(SR_TYPE_COL, tr("Folder")); child->setText(SR_TYPE_COL, tr("Folder"));
@ -1136,7 +1134,7 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_SOURCES_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_SOURCES_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight | Qt::AlignVCenter );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
child->setText(SR_TYPE_COL, tr("Folder")); child->setText(SR_TYPE_COL, tr("Folder"));
@ -1351,7 +1349,7 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
item->setText(SR_SOURCES_COL,modifiedResult); item->setText(SR_SOURCES_COL,modifiedResult);
item->setToolTip(SR_SOURCES_COL, tr("Obtained via ")+QString::fromStdString(rsPeers->getPeerName(file.id)) ); item->setToolTip(SR_SOURCES_COL, tr("Obtained via ")+QString::fromStdString(rsPeers->getPeerName(file.id)) );
item->setData(SR_SOURCES_COL, ROLE_SORT, fltRes); item->setData(SR_SOURCES_COL, ROLE_SORT, fltRes);
item->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight ); item->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight | Qt::AlignVCenter );
item->setText(SR_SEARCH_ID_COL, sid_hexa); item->setText(SR_SEARCH_ID_COL, sid_hexa);
QColor foreground; QColor foreground;
@ -1630,26 +1628,3 @@ void SearchDialog::openFolderSearch()
} }
} }
} }
void SearchDialog::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void SearchDialog::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 12).toInt();
#endif
QFont newFont = ui.searchSummaryWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui.searchSummaryWidget->setFont(newFont);
ui.searchResultWidget->setFont(newFont);
}
}

View file

@ -25,6 +25,7 @@
#include "retroshare/rsevents.h" #include "retroshare/rsevents.h"
#include "ui_SearchDialog.h" #include "ui_SearchDialog.h"
#include "retroshare-gui/mainpage.h" #include "retroshare-gui/mainpage.h"
#include "util/FontSizeHandler.h"
class AdvancedSearchDialog; class AdvancedSearchDialog;
class RSTreeWidgetItemCompareRole; class RSTreeWidgetItemCompareRole;
@ -66,9 +67,6 @@ public:
void updateFiles(qulonglong request_id, const FileDetail& file) ; void updateFiles(qulonglong request_id, const FileDetail& file) ;
protected:
virtual void showEvent(QShowEvent *) override;
private slots: private slots:
/** Create the context popup menu and it's submenus */ /** Create the context popup menu and it's submenus */
@ -119,8 +117,6 @@ private slots:
void filterItems(); void filterItems();
void updateFontSize();
private: private:
/** render the results to the tree widget display */ /** render the results to the tree widget display */
void initSearchResult(const QString& txt,qulonglong searchId, int fileType, bool advanced) ; void initSearchResult(const QString& txt,qulonglong searchId, int fileType, bool advanced) ;
@ -178,6 +174,8 @@ private:
QAction *collViewAct; QAction *collViewAct;
QAction *collOpenAct; QAction *collOpenAct;
FontSizeHandler mFontSizeHandler;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::SearchDialog ui; Ui::SearchDialog ui;

View file

@ -170,17 +170,14 @@ IdDialog::IdDialog(QWidget *parent)
ownItem = new QTreeWidgetItem(); ownItem = new QTreeWidgetItem();
ownItem->setText(RSID_COL_NICKNAME, tr("My own identities")); ownItem->setText(RSID_COL_NICKNAME, tr("My own identities"));
ownItem->setFont(RSID_COL_NICKNAME, ui->idTreeWidget->font());
ownItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff); // this is in order to prevent displaying a reputaiton icon next to these items. ownItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff); // this is in order to prevent displaying a reputaiton icon next to these items.
allItem = new QTreeWidgetItem(); allItem = new QTreeWidgetItem();
allItem->setText(RSID_COL_NICKNAME, tr("All")); allItem->setText(RSID_COL_NICKNAME, tr("All"));
allItem->setFont(RSID_COL_NICKNAME, ui->idTreeWidget->font());
allItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff); allItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff);
contactsItem = new QTreeWidgetItem(); contactsItem = new QTreeWidgetItem();
contactsItem->setText(RSID_COL_NICKNAME, tr("My contacts")); contactsItem->setText(RSID_COL_NICKNAME, tr("My contacts"));
contactsItem->setFont(RSID_COL_NICKNAME, ui->idTreeWidget->font());
contactsItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff); contactsItem->setData(RSID_COL_VOTES, Qt::DecorationRole,0xff);
@ -415,6 +412,45 @@ IdDialog::IdDialog(QWidget *parent)
updateIdTimer.setSingleShot(true); updateIdTimer.setSingleShot(true);
connect(&updateIdTimer, SIGNAL(timeout()), this, SLOT(updateIdList())); connect(&updateIdTimer, SIGNAL(timeout()), this, SLOT(updateIdList()));
mFontSizeHandler.registerFontSize(ui->idTreeWidget, 0, [this] (QAbstractItemView*, int fontSize) {
// Set new font size on all items
QTreeWidgetItemIterator it(ui->idTreeWidget);
while (*it) {
QTreeWidgetItem *item = *it;
if (item->parent()) {
QFont font = item->font(CIRCLEGROUP_CIRCLE_COL_GROUPNAME);
font.setPointSize(fontSize);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, font);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPID, font);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, font);
}
++it;
}
});
mFontSizeHandler.registerFontSize(ui->treeWidget_membership, 0, [this] (QAbstractItemView*, int fontSize) {
// Set new font size on all items
QTreeWidgetItemIterator it(ui->treeWidget_membership);
while (*it) {
QTreeWidgetItem *item = *it;
#ifdef CIRCLE_MEMBERSHIP_CATEGORIES
if (item->parent())
{
#endif
QFont font = item->font(CIRCLEGROUP_CIRCLE_COL_GROUPNAME);
font.setPointSize(fontSize);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, font);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPID, font);
item->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, font);
#ifdef CIRCLE_MEMBERSHIP_CATEGORIES
}
#endif
++it;
}
});
} }
void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
@ -664,7 +700,6 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
{ {
mExternalOtherCircleItem = new QTreeWidgetItem(); mExternalOtherCircleItem = new QTreeWidgetItem();
mExternalOtherCircleItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Other circles")); mExternalOtherCircleItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Other circles"));
mExternalOtherCircleItem->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, ui->treeWidget_membership->font());
ui->treeWidget_membership->addTopLevelItem(mExternalOtherCircleItem); ui->treeWidget_membership->addTopLevelItem(mExternalOtherCircleItem);
} }
@ -672,7 +707,6 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
{ {
mExternalBelongingCircleItem = new QTreeWidgetItem(); mExternalBelongingCircleItem = new QTreeWidgetItem();
mExternalBelongingCircleItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Circles I belong to")); mExternalBelongingCircleItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Circles I belong to"));
mExternalBelongingCircleItem->setFont(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, ui->treeWidget_membership->font());
ui->treeWidget_membership->addTopLevelItem(mExternalBelongingCircleItem); ui->treeWidget_membership->addTopLevelItem(mExternalBelongingCircleItem);
} }
#endif #endif
@ -956,10 +990,6 @@ void IdDialog::showEvent(QShowEvent *s)
needUpdateCirclesOnNextShow = false; needUpdateCirclesOnNextShow = false;
MainPage::showEvent(s); MainPage::showEvent(s);
if (!s->spontaneous()) {
updateFontSize();
}
} }
void IdDialog::createExternalCircle() void IdDialog::createExternalCircle()
@ -2603,22 +2633,3 @@ void IdDialog::restoreExpandedCircleItems(const std::vector<bool>& expanded_root
restoreTopLevel(mExternalOtherCircleItem,1); restoreTopLevel(mExternalOtherCircleItem,1);
restoreTopLevel(mMyCircleItem,2); restoreTopLevel(mMyCircleItem,2);
} }
void IdDialog::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui->idTreeWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui->idTreeWidget->setFont(newFont);
ui->treeWidget_membership->setFont(newFont);
contactsItem->setFont(RSID_COL_NICKNAME, newFont);
allItem->setFont(RSID_COL_NICKNAME, newFont);
ownItem->setFont(RSID_COL_NICKNAME, newFont);
}
}

View file

@ -22,6 +22,7 @@
#define IDENTITYDIALOG_H #define IDENTITYDIALOG_H
#include "gui/gxs/RsGxsUpdateBroadcastPage.h" #include "gui/gxs/RsGxsUpdateBroadcastPage.h"
#include "util/FontSizeHandler.h"
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
@ -113,8 +114,6 @@ private slots:
static QString inviteMessage(); static QString inviteMessage();
void sendInvite(); void sendInvite();
void updateFontSize();
private: private:
void processSettings(bool load); void processSettings(bool load);
QString createUsageString(const RsIdentityUsage& u) const; QString createUsageString(const RsIdentityUsage& u) const;
@ -159,6 +158,8 @@ private:
bool needUpdateIdsOnNextShow; bool needUpdateIdsOnNextShow;
bool needUpdateCirclesOnNextShow; bool needUpdateCirclesOnNextShow;
FontSizeHandler mFontSizeHandler;
/* UI - Designer */ /* UI - Designer */
Ui::IdDialog *ui; Ui::IdDialog *ui;
}; };

View file

@ -67,7 +67,6 @@
#include "notifyqt.h" #include "notifyqt.h"
#include "common/UserNotify.h" #include "common/UserNotify.h"
#include "gui/ServicePermissionDialog.h" #include "gui/ServicePermissionDialog.h"
#include "gui/settings/rsharesettings.h"
#ifdef UNFINISHED #ifdef UNFINISHED
#include "unfinished/ApplicationWindow.h" #include "unfinished/ApplicationWindow.h"
@ -361,6 +360,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
connect(NotifyQt::getInstance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); connect(NotifyQt::getInstance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
settingsChanged(); settingsChanged();
mFontSizeHandler.registerFontSize(ui->listWidget, 1.5f);
} }
/** Destructor. */ /** Destructor. */
@ -1642,8 +1643,6 @@ void MainWindow::settingsChanged()
ui->toolBarAction->setIconSize(QSize(toolSize,toolSize)); ui->toolBarAction->setIconSize(QSize(toolSize,toolSize));
int itemSize = Settings->getListItemIconSize(); int itemSize = Settings->getListItemIconSize();
ui->listWidget->setIconSize(QSize(itemSize,itemSize)); ui->listWidget->setIconSize(QSize(itemSize,itemSize));
updateFontSize();
} }
void MainWindow::externalLinkActivated(const QUrl &url) void MainWindow::externalLinkActivated(const QUrl &url)
@ -1823,23 +1822,6 @@ void MainWindow::setCompactStatusMode(bool compact)
//opModeStatus: TODO Show only ??? //opModeStatus: TODO Show only ???
} }
void MainWindow::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui->listWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
int iconHeight = fontMetrics.height()*1.5;
ui->listWidget->setFont(newFont);
ui->listWidget->setIconSize(QSize(iconHeight, iconHeight));
}
}
Gui_InputDialogReturn MainWindow::guiInputDialog(const QString& windowTitle, const QString& labelText, QLineEdit::EchoMode textEchoMode, bool modal) Gui_InputDialogReturn MainWindow::guiInputDialog(const QString& windowTitle, const QString& labelText, QLineEdit::EchoMode textEchoMode, bool modal)
{ {

View file

@ -27,6 +27,7 @@
#include "gui/common/rwindow.h" #include "gui/common/rwindow.h"
#include "gui/common/RSComboBox.h" #include "gui/common/RSComboBox.h"
#include "util/FontSizeHandler.h"
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -307,7 +308,6 @@ private slots:
void doQuit(); void doQuit();
void updateTrayCombine(); void updateTrayCombine();
void updateFontSize();
private: private:
void initStackedPage(); void initStackedPage();
@ -372,6 +372,8 @@ private:
void setIdle(bool Idle); void setIdle(bool Idle);
bool isIdle; bool isIdle;
FontSizeHandler mFontSizeHandler;
Ui::MainWindow *ui ; Ui::MainWindow *ui ;
}; };

View file

@ -88,11 +88,16 @@ class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate
public: public:
virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const
{ {
painter->save();
QStyleOptionViewItem opt(option) ; QStyleOptionViewItem opt(option) ;
setPainterOptions(painter,opt,index) ; setPainterOptions(painter,opt,index) ;
if(index.data().toLongLong() > 0) // no date is present. if(index.data().toLongLong() > 0) { // no date is present.
painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ; painter->setFont(opt.font);
painter->drawText(opt.rect, opt.displayAlignment, misc::timeRelativeToNow(index.data().toLongLong())) ;
}
painter->restore();
} }
}; };
@ -101,10 +106,14 @@ class RSHumanReadableSizeDelegate: public RSHumanReadableDelegate
public: public:
virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const
{ {
painter->save();
QStyleOptionViewItem opt(option) ; QStyleOptionViewItem opt(option) ;
setPainterOptions(painter,opt,index) ; setPainterOptions(painter,opt,index) ;
painter->drawText(opt.rect, Qt::AlignRight, misc::friendlyUnit(index.data().toULongLong())); painter->setFont(opt.font);
painter->drawText(opt.rect, opt.displayAlignment, misc::friendlyUnit(index.data().toULongLong()));
painter->restore();
} }
}; };

View file

@ -208,6 +208,8 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
connect(unsubscribeButton, SIGNAL(clicked()), this , SLOT(leaveLobby())); connect(unsubscribeButton, SIGNAL(clicked()), this , SLOT(leaveLobby()));
getChatWidget()->addTitleBarWidget(unsubscribeButton) ; getChatWidget()->addTitleBarWidget(unsubscribeButton) ;
mFontSizeHandler.registerFontSize(ui.participantsList);
} }
void ChatLobbyDialog::leaveLobby() void ChatLobbyDialog::leaveLobby()
@ -1017,25 +1019,3 @@ void ChatLobbyDialog::setWindowed(bool windowed)
if (chatLobbyPage)// If not defined, we are on autosubscribe loop of lobby widget constructor. So don't recall it. if (chatLobbyPage)// If not defined, we are on autosubscribe loop of lobby widget constructor. So don't recall it.
showDialog(RS_CHAT_FOCUS); showDialog(RS_CHAT_FOCUS);
} }
void ChatLobbyDialog::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void ChatLobbyDialog::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui.participantsList->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui.participantsList->setFont(newFont);
}
}

View file

@ -26,6 +26,7 @@
#include "gui/common/RSTreeWidgetItem.h" #include "gui/common/RSTreeWidgetItem.h"
#include "ChatDialog.h" #include "ChatDialog.h"
#include "PopupChatWindow.h" #include "PopupChatWindow.h"
#include "util/FontSizeHandler.h"
// Q_DECLARE_METATYPE(RsGxsId) // Q_DECLARE_METATYPE(RsGxsId)
// Q_DECLARE_METATYPE(QList<RsGxsId>) // Q_DECLARE_METATYPE(QList<RsGxsId>)
@ -54,8 +55,6 @@ public:
inline bool isWindowed() const { return dynamic_cast<PopupChatWindow*>(this->window()) != nullptr; } inline bool isWindowed() const { return dynamic_cast<PopupChatWindow*>(this->window()) != nullptr; }
virtual void showEvent(QShowEvent *) ;
public slots: public slots:
void leaveLobby() ; void leaveLobby() ;
private slots: private slots:
@ -66,7 +65,6 @@ private slots:
void showInPeopleTab(); void showInPeopleTab();
void toggleWindowed(){setWindowed(!isWindowed());} void toggleWindowed(){setWindowed(!isWindowed());}
void setWindowed(bool windowed); void setWindowed(bool windowed);
void updateFontSize();
signals: signals:
void typingEventReceived(ChatLobbyId) ; void typingEventReceived(ChatLobbyId) ;
@ -118,6 +116,8 @@ private:
bool mWindowedSetted; bool mWindowedSetted;
PopupChatWindow* mPCWindow; PopupChatWindow* mPCWindow;
FontSizeHandler mFontSizeHandler;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::ChatLobbyDialog ui; Ui::ChatLobbyDialog ui;

View file

@ -28,7 +28,6 @@
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/common/RSTreeWidgetItem.h" #include "gui/common/RSTreeWidgetItem.h"
#include "gui/common/StatusDefs.h" #include "gui/common/StatusDefs.h"
#include "gui/settings/rsharesettings.h"
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "gui/common/PeerDefs.h" #include "gui/common/PeerDefs.h"
#include "gui/common/GroupDefs.h" #include "gui/common/GroupDefs.h"
@ -136,6 +135,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
mEventHandlerId_peers = 0; mEventHandlerId_peers = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) {
RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }) ;}, mEventHandlerId_peers, RsEventType::PEER_CONNECTION ); RsQThreadUtils::postToObject( [this,event]() { handleEvent_main_thread(event); }) ;}, mEventHandlerId_peers, RsEventType::PEER_CONNECTION );
mFontSizeHandler.registerFontSize(ui->friendList);
} }
void FriendSelectionWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void FriendSelectionWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
@ -224,8 +225,6 @@ void FriendSelectionWidget::showEvent(QShowEvent */*e*/)
{ {
if(gxsIds.empty()) if(gxsIds.empty())
loadIdentities(); loadIdentities();
updateFontSize();
} }
void FriendSelectionWidget::start() void FriendSelectionWidget::start()
{ {
@ -1274,18 +1273,3 @@ bool FriendSelectionWidget::isFilterConnected()
{ {
return mActionFilterConnected->isChecked(); return mActionFilterConnected->isChecked();
} }
void FriendSelectionWidget::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui->friendList->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui->friendList->setFont(newFont);
}
}

View file

@ -26,6 +26,7 @@
#include "retroshare/rsevents.h" #include "retroshare/rsevents.h"
#include <gui/gxs/RsGxsUpdateBroadcastPage.h> #include <gui/gxs/RsGxsUpdateBroadcastPage.h>
#include "util/FontSizeHandler.h"
namespace Ui { namespace Ui {
class FriendSelectionWidget; class FriendSelectionWidget;
@ -144,7 +145,6 @@ private slots:
void itemChanged(QTreeWidgetItem *item, int column); void itemChanged(QTreeWidgetItem *item, int column);
void selectAll() ; void selectAll() ;
void deselectAll() ; void deselectAll() ;
void updateFontSize();
private: private:
void fillList(); void fillList();
@ -179,6 +179,8 @@ private:
std::set<std::string> mPreSelectedIds; // because loading of GxsIds is asynchroneous we keep selected Ids from the client in a list here and use it to initialize after loading them. std::set<std::string> mPreSelectedIds; // because loading of GxsIds is asynchroneous we keep selected Ids from the client in a list here and use it to initialize after loading them.
FontSizeHandler mFontSizeHandler;
RsEventsHandlerId_t mEventHandlerId_identities; RsEventsHandlerId_t mEventHandlerId_identities;
RsEventsHandlerId_t mEventHandlerId_peers; RsEventsHandlerId_t mEventHandlerId_peers;
}; };

View file

@ -30,12 +30,10 @@
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "util/DateTime.h" #include "util/DateTime.h"
#include "gui/notifyqt.h"
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QMenu> #include <QMenu>
#include <QToolButton> #include <QToolButton>
#include <QShowEvent>
#include <stdint.h> #include <stdint.h>
@ -69,8 +67,6 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(itemActivated(QTreeWidgetItem*,int))); connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(itemActivated(QTreeWidgetItem*,int)));
} }
updateFontSize();
int H = QFontMetricsF(ui->treeWidget->font()).height() ; int H = QFontMetricsF(ui->treeWidget->font()).height() ;
#if QT_VERSION < QT_VERSION_CHECK(5,11,0) #if QT_VERSION < QT_VERSION_CHECK(5,11,0)
int W = QFontMetricsF(ui->treeWidget->font()).width("_") ; int W = QFontMetricsF(ui->treeWidget->font()).width("_") ;
@ -152,7 +148,19 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
connect(ui->distantSearchLineEdit,SIGNAL(returnPressed()),this,SLOT(distantSearch())) ; connect(ui->distantSearchLineEdit,SIGNAL(returnPressed()),this,SLOT(distantSearch())) ;
ui->treeWidget->setIconSize(QSize(H*1.8,H*1.8)); mFontSizeHandler.registerFontSize(ui->treeWidget, 1.8f, [this] (QAbstractItemView*, int fontSize) {
// Set new font size on all items
QTreeWidgetItemIterator it(ui->treeWidget);
while (*it) {
QTreeWidgetItem *item = *it;
QFont font = item->font(GTW_COLUMN_NAME);
font.setPointSize(fontSize);
item->setFont(GTW_COLUMN_NAME, font);
++it;
}
});
} }
GroupTreeWidget::~GroupTreeWidget() GroupTreeWidget::~GroupTreeWidget()
@ -258,8 +266,8 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
RSTreeWidgetItem *item = new RSTreeWidgetItem(); RSTreeWidgetItem *item = new RSTreeWidgetItem();
ui->treeWidget->addTopLevelItem(item); ui->treeWidget->addTopLevelItem(item);
// To get StyleSheet for Items // To get StyleSheet for Items
ui->treeWidget->style()->unpolish(ui->treeWidget); // ui->treeWidget->style()->unpolish(ui->treeWidget);
ui->treeWidget->style()->polish(ui->treeWidget); // ui->treeWidget->style()->polish(ui->treeWidget);
item->setText(GTW_COLUMN_NAME, name); item->setText(GTW_COLUMN_NAME, name);
item->setData(GTW_COLUMN_DATA, ROLE_NAME, name); item->setData(GTW_COLUMN_DATA, ROLE_NAME, name);
@ -394,7 +402,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
if (item == NULL) { if (item == NULL) {
item = new RSTreeWidgetItem(compareRole); item = new RSTreeWidgetItem(compareRole);
item->setData(GTW_COLUMN_DATA, ROLE_ID, itemInfo.id); item->setData(GTW_COLUMN_DATA, ROLE_ID, itemInfo.id);
item->setFont(GTW_COLUMN_DATA, ui->treeWidget->font()); item->setFont(GTW_COLUMN_NAME, ui->treeWidget->font());
//static_cast<RSTreeWidgetItem*>(item)->setNoDataAsLast(true); //Uncomment this to sort data with QVariant() always at end. //static_cast<RSTreeWidgetItem*>(item)->setNoDataAsLast(true); //Uncomment this to sort data with QVariant() always at end.
categoryItem->addChild(item); categoryItem->addChild(item);
} }
@ -671,28 +679,3 @@ void GroupTreeWidget::sort()
{ {
ui->treeWidget->resort(); ui->treeWidget->resort();
} }
void GroupTreeWidget::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void GroupTreeWidget::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui->treeWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui->treeWidget->setFont(newFont);
int H = QFontMetricsF(ui->treeWidget->font()).height() ;
ui->treeWidget->setIconSize(QSize(H*1.8,H*1.8));
}
}

View file

@ -25,12 +25,12 @@
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QDateTime> #include <QDateTime>
#include "util/FontSizeHandler.h"
class QToolButton; class QToolButton;
class RshareSettings; class RshareSettings;
class RSTreeWidgetItemCompareRole; class RSTreeWidgetItemCompareRole;
class RSTreeWidget; class RSTreeWidget;
class QShowEvent;
#define GROUPTREEWIDGET_COLOR_STANDARD -1 #define GROUPTREEWIDGET_COLOR_STANDARD -1
#define GROUPTREEWIDGET_COLOR_CATEGORY 0 #define GROUPTREEWIDGET_COLOR_CATEGORY 0
@ -143,7 +143,6 @@ signals:
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
virtual void showEvent(QShowEvent *) override;
private slots: private slots:
void customContextMenuRequested(const QPoint &pos); void customContextMenuRequested(const QPoint &pos);
@ -153,7 +152,6 @@ private slots:
void distantSearch(); void distantSearch();
void sort(); void sort();
void updateFontSize();
private: private:
void calculateScore(QTreeWidgetItem *item, const QString &filterText); void calculateScore(QTreeWidgetItem *item, const QString &filterText);
@ -166,6 +164,7 @@ private:
// Compare role used for each column // Compare role used for each column
RSTreeWidgetItemCompareRole *compareRole; RSTreeWidgetItemCompareRole *compareRole;
FontSizeHandler mFontSizeHandler;
Ui::GroupTreeWidget *ui; Ui::GroupTreeWidget *ui;
}; };

View file

@ -55,7 +55,6 @@
#include "gui/connect/ConnectProgressDialog.h" #include "gui/connect/ConnectProgressDialog.h"
#include "gui/common/ElidedLabel.h" #include "gui/common/ElidedLabel.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/settings/rsharesettings.h"
#include "NewFriendList.h" #include "NewFriendList.h"
#include "ui_NewFriendList.h" #include "ui_NewFriendList.h"
@ -274,6 +273,8 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)),Qt::QueuedConnection); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)),Qt::QueuedConnection);
connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint)));
mFontSizeHandler.registerFontSize(ui->peerTreeWidget,1.5f);
// #ifdef RS_DIRECT_CHAT // #ifdef RS_DIRECT_CHAT
// connect(ui->peerTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(chatNode())); // connect(ui->peerTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(chatNode()));
// #endif // #endif
@ -1694,27 +1695,3 @@ void NewFriendList::expandGroup(const RsNodeGroupId& gid)
QModelIndex index = mProxyModel->mapFromSource(mModel->getIndexOfGroup(gid)); QModelIndex index = mProxyModel->mapFromSource(mModel->getIndexOfGroup(gid));
ui->peerTreeWidget->setExpanded(index,true) ; ui->peerTreeWidget->setExpanded(index,true) ;
} }
void NewFriendList::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void NewFriendList::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui->peerTreeWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
int iconHeight = fontMetrics.height()*1.5;
ui->peerTreeWidget->setFont(newFont);
ui->peerTreeWidget->setIconSize(QSize(iconHeight, iconHeight));
}
}

View file

@ -29,6 +29,7 @@
#include "FriendListModel.h" #include "FriendListModel.h"
#include "retroshare/rsstatus.h" #include "retroshare/rsstatus.h"
#include "util/FontSizeHandler.h"
namespace Ui { namespace Ui {
class NewFriendList; class NewFriendList;
@ -54,8 +55,6 @@ public:
explicit NewFriendList(QWidget *parent = 0); explicit NewFriendList(QWidget *parent = 0);
~NewFriendList(); ~NewFriendList();
virtual void showEvent(QShowEvent *) ;
// Add a tool button to the tool area // Add a tool button to the tool area
void addToolButton(QToolButton *toolButton); void addToolButton(QToolButton *toolButton);
void processSettings(bool load); void processSettings(bool load);
@ -97,7 +96,6 @@ private slots:
void sortColumn(int col,Qt::SortOrder so); void sortColumn(int col,Qt::SortOrder so);
void itemExpanded(const QModelIndex&); void itemExpanded(const QModelIndex&);
void itemCollapsed(const QModelIndex&); void itemCollapsed(const QModelIndex&);
void updateFontSize();
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
@ -107,6 +105,7 @@ private:
Ui::NewFriendList *ui; Ui::NewFriendList *ui;
RsFriendListModel *mModel; RsFriendListModel *mModel;
QAction *mActionSortByState; QAction *mActionSortByState;
FontSizeHandler mFontSizeHandler;
void applyWhileKeepingTree(std::function<void()> predicate); void applyWhileKeepingTree(std::function<void()> predicate);

View file

@ -46,6 +46,7 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
: QAbstractItemModel(parent), mUseChildTS(false),mFilteringEnabled(false),mTreeMode(TREE_MODE_TREE) : QAbstractItemModel(parent), mUseChildTS(false),mFilteringEnabled(false),mTreeMode(TREE_MODE_TREE)
{ {
initEmptyHierarchy(mPosts); initEmptyHierarchy(mPosts);
mFont = QApplication::font();
} }
void RsGxsForumModel::preMods() void RsGxsForumModel::preMods()
@ -399,7 +400,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
if(role == Qt::FontRole) if(role == Qt::FontRole)
{ {
QFont font ; QFont font = mFont;
font.setBold( (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN) || IS_MSG_UNREAD(fmpe.mMsgStatus)); font.setBold( (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN) || IS_MSG_UNREAD(fmpe.mMsgStatus));
return QVariant(font); return QVariant(font);
} }
@ -533,6 +534,15 @@ void RsGxsForumModel::setFilter(int column,const QStringList& strings,uint32_t&
postMods(); postMods();
} }
void RsGxsForumModel::setFont(const QFont &font)
{
preMods();
mFont = font;
postMods();
}
QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int /*column*/) const QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int /*column*/) const
{ {
if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_MISSING) if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_MISSING)
@ -562,7 +572,7 @@ QVariant RsGxsForumModel::toolTipRole(const ForumModelPostEntry& fmpe,int column
if(!GxsIdDetails::MakeIdDesc(fmpe.mAuthorId, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) if(!GxsIdDetails::MakeIdDesc(fmpe.mAuthorId, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR))
return QVariant(); return QVariant();
int S = QFontMetricsF(QApplication::font()).height(); int S = QFontMetricsF(mFont).height();
QImage pix( (*icons.begin()).pixmap(QSize(5*S,5*S)).toImage()); QImage pix( (*icons.begin()).pixmap(QSize(5*S,5*S)).toImage());
QString embeddedImage; QString embeddedImage;
@ -599,7 +609,7 @@ QVariant RsGxsForumModel::backgroundRole(const ForumModelPostEntry& fmpe,int /*c
QVariant RsGxsForumModel::sizeHintRole(int col) const QVariant RsGxsForumModel::sizeHintRole(int col) const
{ {
float factor = QFontMetricsF(QApplication::font()).height()/14.0f ; float factor = QFontMetricsF(mFont).height()/14.0f ;
switch(col) switch(col)
{ {
@ -650,7 +660,7 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
case COLUMN_THREAD_TITLE: if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_REDACTED) case COLUMN_THREAD_TITLE: if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_REDACTED)
return QVariant(tr("[ ... Redacted message ... ]")); return QVariant(tr("[ ... Redacted message ... ]"));
// else if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED) // else if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED)
// return QVariant( QString("<img src=\":/icons/pinned_64.png\" height=%1/>").arg(QFontMetricsF(QFont()).height()) // return QVariant( QString("<img src=\":/icons/pinned_64.png\" height=%1/>").arg(QFontMetricsF(mFont).height())
// + QString::fromUtf8(fmpe.mTitle.c_str())); // + QString::fromUtf8(fmpe.mTitle.c_str()));
else else
return QVariant(QString::fromUtf8(fmpe.mTitle.c_str())); return QVariant(QString::fromUtf8(fmpe.mTitle.c_str()));

View file

@ -22,6 +22,7 @@
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include <QModelIndex> #include <QModelIndex>
#include <QColor> #include <QColor>
#include <QFont>
struct ForumModelPostEntry: public ForumPostEntry struct ForumModelPostEntry: public ForumPostEntry
{ {
@ -76,6 +77,7 @@ public:
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
static const QString FilterString ; static const QString FilterString ;
void setFont(const QFont &font);
std::vector<std::pair<rstime_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const; std::vector<std::pair<rstime_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
@ -185,6 +187,7 @@ private:
QColor mBackgroundColorPinned; QColor mBackgroundColorPinned;
QColor mBackgroundColorFiltered; QColor mBackgroundColorFiltered;
QFont mFont;
friend class const_iterator; friend class const_iterator;
}; };

View file

@ -250,7 +250,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
ui->setupUi(this); ui->setupUi(this);
//setUpdateWhenInvisible(true); //setUpdateWhenInvisible(true);
updateFontSize();
//mUpdating = false; //mUpdating = false;
mUnreadCount = 0; mUnreadCount = 0;
@ -308,10 +307,10 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
connect(ui->latestPostInThreadView_TB, SIGNAL(toggled(bool)), this, SLOT(toggleLstPostInThreadView(bool))); connect(ui->latestPostInThreadView_TB, SIGNAL(toggled(bool)), this, SLOT(toggleLstPostInThreadView(bool)));
/* Set own item delegate */ /* Set own item delegate */
//RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this); RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this);
//itemDelegate->setSpacing(QSize(0, 2)); itemDelegate->setSpacing(QSize(0, 2));
//itemDelegate->setOnlyPlainText(true); itemDelegate->setOnlyPlainText(true);
//ui->threadTreeWidget->setItemDelegate(itemDelegate); ui->threadTreeWidget->setItemDelegate(itemDelegate);
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title"));
@ -322,10 +321,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
float f = QFontMetricsF(font()).height()/14.0f ; float f = QFontMetricsF(font()).height()/14.0f ;
QFontMetricsF fontMetrics(ui->threadTreeWidget->font());
int iconHeight = fontMetrics.height() * 1.4;
ui->threadTreeWidget->setIconSize(QSize(iconHeight, iconHeight));
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * ttheader = ui->threadTreeWidget->header () ; QHeaderView * ttheader = ui->threadTreeWidget->header () ;
@ -368,8 +363,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
blankPost(); blankPost();
ui->subscribeToolButton->setToolTip(tr( "<p>Subscribing to the forum will gather \ ui->subscribeToolButton->setToolTip(tr( "<p>Subscribing to the forum will gather \
available posts from your subscribed friends, and make the \ available posts from your subscribed friends, and make the \
forum visible to all other friends.</p><p>Afterwards you can unsubscribe from the context menu of the forum list at left.</p>")); forum visible to all other friends.</p><p>Afterwards you can unsubscribe from the context menu of the forum list at left.</p>"));
@ -383,6 +376,10 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
[this](std::shared_ptr<const RsEvent> event) [this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); }, { RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::GXS_FORUMS ); mEventHandlerId, RsEventType::GXS_FORUMS );
mFontSizeHandler.registerFontSize(ui->threadTreeWidget, 1.4f, [this](QAbstractItemView *view, int) {
mThreadModel->setFont(view->font());
});
} }
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
@ -2102,27 +2099,3 @@ void GxsForumThreadWidget::showAuthorInPeople(const RsGxsForumMsg& msg)
MainWindow::showWindow(MainWindow::People); MainWindow::showWindow(MainWindow::People);
idDialog->navigate(RsGxsId(msg.mMeta.mAuthorId)); idDialog->navigate(RsGxsId(msg.mMeta.mAuthorId));
} }
void GxsForumThreadWidget::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void GxsForumThreadWidget::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 12).toInt();
#endif
QFont newFont = ui->threadTreeWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui->threadTreeWidget->setFont(newFont);
int iconHeight = fontMetrics.height() * 1.4;
ui->threadTreeWidget->setIconSize(QSize(iconHeight, iconHeight));
}
}

View file

@ -26,6 +26,7 @@
#include "gui/gxs/GxsMessageFrameWidget.h" #include "gui/gxs/GxsMessageFrameWidget.h"
#include <retroshare/rsgxsforums.h> #include <retroshare/rsgxsforums.h>
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "util/FontSizeHandler.h"
class QSortFilterProxyModel; class QSortFilterProxyModel;
class QTreeWidgetItem; class QTreeWidgetItem;
@ -97,7 +98,6 @@ public:
protected: protected:
//bool eventFilter(QObject *obj, QEvent *ev); //bool eventFilter(QObject *obj, QEvent *ev);
//void changeEvent(QEvent *e); //void changeEvent(QEvent *e);
virtual void showEvent(QShowEvent *) override;
/* RsGxsUpdateBroadcastWidget */ /* RsGxsUpdateBroadcastWidget */
virtual void updateDisplay(bool complete); virtual void updateDisplay(bool complete);
@ -161,8 +161,6 @@ private slots:
void filterColumnChanged(int column); void filterColumnChanged(int column);
void filterItems(const QString &text); void filterItems(const QString &text);
void updateFontSize();
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
void expandSubtree(); void expandSubtree();
#endif #endif
@ -237,6 +235,8 @@ private:
QSortFilterProxyModel *mThreadProxyModel; QSortFilterProxyModel *mThreadProxyModel;
QList<RsGxsMessageId> mSavedExpandedMessages; QList<RsGxsMessageId> mSavedExpandedMessages;
FontSizeHandler mFontSizeHandler;
Ui::GxsForumThreadWidget *ui; Ui::GxsForumThreadWidget *ui;
RsEventsHandlerId_t mEventHandlerId; RsEventsHandlerId_t mEventHandlerId;
}; };

View file

@ -299,7 +299,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
QFontDatabase db; QFontDatabase db;
foreach(int size, db.standardSizes()) foreach(int size, db.standardSizes())
ui.comboSize->addItem(QString::number(size)); ui.comboSize->addItem(QString::number(size), size);
QStyleOptionComboBox opt; QSize sh; QStyleOptionComboBox opt; QSize sh;
opt.initFrom(ui.comboSize); opt.initFrom(ui.comboSize);
@ -408,6 +408,10 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
ui.hashBox->setDropWidget(this); ui.hashBox->setDropWidget(this);
ui.hashBox->setAutoHide(true); ui.hashBox->setAutoHide(true);
mMessageFontSizeHandler.registerFontSize(ui.msgText, [this, db] (QWidget*, int fontSize) {
ui.comboSize->setCurrentIndex(ui.comboSize->findData(fontSize));
});
#if QT_VERSION < 0x040700 #if QT_VERSION < 0x040700
// embedded images are not supported before QT 4.7.0 // embedded images are not supported before QT 4.7.0
ui.imagebtn->setVisible(false); ui.imagebtn->setVisible(false);
@ -2933,26 +2937,3 @@ void MessageComposer::checkLength()
ui.actionSend->setEnabled(true); ui.actionSend->setEnabled(true);
} }
} }
void MessageComposer::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void MessageComposer::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("Messages", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("Messages", "MinimumFontSize", 12).toInt();
#endif
QFont newFont = ui.msgText->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui.msgText->setFont(newFont);
ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(newFont.pointSize())));
}
}

View file

@ -28,6 +28,7 @@
#include "ui_MessageComposer.h" #include "ui_MessageComposer.h"
#include "gui/msgs/MessageInterface.h" #include "gui/msgs/MessageInterface.h"
#include "util/FontSizeHandler.h"
class QAction; class QAction;
struct RsIdentityDetails; struct RsIdentityDetails;
@ -95,7 +96,6 @@ public slots:
protected: protected:
void closeEvent (QCloseEvent * event); void closeEvent (QCloseEvent * event);
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
virtual void showEvent(QShowEvent *) ;
private slots: private slots:
/* toggle Contacts DockWidget */ /* toggle Contacts DockWidget */
@ -170,7 +170,6 @@ private slots:
static QString inviteMessage(); static QString inviteMessage();
void checkLength(); void checkLength();
void updateFontSize();
private: private:
static QString buildReplyHeader(const MessageInfo &msgInfo); static QString buildReplyHeader(const MessageInfo &msgInfo);
@ -269,6 +268,8 @@ private:
bool has_gxs; bool has_gxs;
bool mAlreadySent; // prevents a Qt bug that calls the same action twice. bool mAlreadySent; // prevents a Qt bug that calls the same action twice.
MessageFontSizeHandler mMessageFontSizeHandler;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::MessageComposer ui; Ui::MessageComposer ui;

View file

@ -57,6 +57,7 @@ RsMessageModel::RsMessageModel(QObject *parent)
mQuickViewFilter = QUICK_VIEW_ALL; mQuickViewFilter = QUICK_VIEW_ALL;
mFilterType = FILTER_TYPE_NONE; mFilterType = FILTER_TYPE_NONE;
mFilterStrings.clear(); mFilterStrings.clear();
mFont = QApplication::font();
} }
void RsMessageModel::preMods() void RsMessageModel::preMods()
@ -248,7 +249,7 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const
if(role == Qt::FontRole) if(role == Qt::FontRole)
{ {
QFont font ; QFont font = mFont;
font.setBold(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)); font.setBold(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER));
return QVariant(font); return QVariant(font);
@ -404,6 +405,15 @@ void RsMessageModel::setFilter(FilterType filter_type, const QStringList& string
emit dataChanged(createIndex(0,0),createIndex(rowCount()-1,RsMessageModel::columnCount()-1)); emit dataChanged(createIndex(0,0),createIndex(rowCount()-1,RsMessageModel::columnCount()-1));
} }
void RsMessageModel::setFont(const QFont &font)
{
mFont = font;
if (rowCount() > 0) {
emit dataChanged(createIndex(0,0), createIndex(rowCount() - 1, RsMessageModel::columnCount() - 1));
}
}
QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
{ {
if(column == COLUMN_THREAD_AUTHOR || column == COLUMN_THREAD_TO) if(column == COLUMN_THREAD_AUTHOR || column == COLUMN_THREAD_TO)
@ -440,7 +450,7 @@ QVariant RsMessageModel::backgroundRole(const Rs::Msgs::MsgInfoSummary &/*fmpe*/
QVariant RsMessageModel::sizeHintRole(int col) const QVariant RsMessageModel::sizeHintRole(int col) const
{ {
float factor = QFontMetricsF(QApplication::font()).height()/14.0f ; float factor = QFontMetricsF(mFont).height()/14.0f ;
switch(col) switch(col)
{ {

View file

@ -22,6 +22,7 @@
#include <QModelIndex> #include <QModelIndex>
#include <QColor> #include <QColor>
#include <QFont>
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
@ -104,6 +105,7 @@ public:
void setQuickViewFilter(QuickViewFilter fn) ; void setQuickViewFilter(QuickViewFilter fn) ;
void setFilter(FilterType filter_type, const QStringList& strings) ; void setFilter(FilterType filter_type, const QStringList& strings) ;
void setFont(const QFont &font);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@ -184,6 +186,7 @@ private:
QuickViewFilter mQuickViewFilter ; QuickViewFilter mQuickViewFilter ;
QStringList mFilterStrings; QStringList mFilterStrings;
FilterType mFilterType; FilterType mFilterType;
QFont mFont;
std::vector<Rs::Msgs::MsgInfoSummary> mMessages; std::vector<Rs::Msgs::MsgInfoSummary> mMessages;
std::map<std::string,uint32_t> mMessagesMap; std::map<std::string,uint32_t> mMessagesMap;

View file

@ -163,9 +163,9 @@ MessagesDialog::MessagesDialog(QWidget *parent)
changeBox(0); // set to inbox changeBox(0); // set to inbox
//RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this); RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this);
//itemDelegate->setSpacing(QSize(0, 2)); itemDelegate->setSpacing(QSize(0, 2));
//ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_SUBJECT,itemDelegate); ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_SUBJECT,itemDelegate);
ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_AUTHOR,new GxsIdTreeItemDelegate()) ; ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_AUTHOR,new GxsIdTreeItemDelegate()) ;
ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_TO,new GxsIdTreeItemDelegate()) ; ui.messageTreeWidget->setItemDelegateForColumn(RsMessageModel::COLUMN_THREAD_TO,new GxsIdTreeItemDelegate()) ;
@ -306,6 +306,23 @@ MessagesDialog::MessagesDialog(QWidget *parent)
mTagEventHandlerId = 0; mTagEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [this,event]() { handleTagEvent_main_thread(event); }); }, mEventHandlerId, RsEventType::MAIL_TAG ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [this,event]() { handleTagEvent_main_thread(event); }); }, mEventHandlerId, RsEventType::MAIL_TAG );
mFontSizeHandler.registerFontSize(ui.listWidget, 1.5f, [this] (QAbstractItemView*, int fontSize) {
// Set new font size on all items
QList<int> rows;
rows << ROW_INBOX << ROW_OUTBOX << ROW_DRAFTBOX;
foreach (int row, rows) {
QListWidgetItem *item = ui.listWidget->item(row);
QFont font = item->font();
font.setPointSize(fontSize);
item->setFont(font);
}
});
mFontSizeHandler.registerFontSize(ui.quickViewWidget, 1.5f);
mFontSizeHandler.registerFontSize(ui.messageTreeWidget, 1.5f, [this] (QAbstractItemView *view, int) {
mMessageModel->setFont(view->font());
});
} }
void MessagesDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void MessagesDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
@ -1660,32 +1677,3 @@ void MessagesDialog::updateInterface()
ui.tabWidget->setTabIcon(0, FilesDefs::getIconFromQtResourcePath(":/icons/warning_yellow_128.png")); ui.tabWidget->setTabIcon(0, FilesDefs::getIconFromQtResourcePath(":/icons/warning_yellow_128.png"));
} }
} }
void MessagesDialog::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void MessagesDialog::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui.listWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
int iconHeight = fontMetrics.height()*1.5;
ui.listWidget->setFont(newFont);
ui.quickViewWidget->setFont(newFont);
ui.messageTreeWidget->setFont(newFont);
ui.listWidget->setIconSize(QSize(iconHeight, iconHeight));
ui.quickViewWidget->setIconSize(QSize(iconHeight, iconHeight));
ui.messageTreeWidget->setIconSize(QSize(iconHeight, iconHeight));
}
}

View file

@ -25,6 +25,7 @@
#include <retroshare/rsevents.h> #include <retroshare/rsevents.h>
#include <retroshare-gui/mainpage.h> #include <retroshare-gui/mainpage.h>
#include "util/FontSizeHandler.h"
#include "ui_MessagesDialog.h" #include "ui_MessagesDialog.h"
@ -54,7 +55,6 @@ public:
// replaced by shortcut // replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ; // virtual void keyPressEvent(QKeyEvent *) ;
virtual void showEvent(QShowEvent *) ;
QColor textColorInbox() const { return mTextColorInbox; } QColor textColorInbox() const { return mTextColorInbox; }
@ -111,8 +111,6 @@ private slots:
void tabChanged(int tab); void tabChanged(int tab);
void tabCloseRequested(int tab); void tabCloseRequested(int tab);
void updateFontSize();
private: private:
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event); void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
void handleTagEvent_main_thread(std::shared_ptr<const RsEvent> event); void handleTagEvent_main_thread(std::shared_ptr<const RsEvent> event);
@ -169,6 +167,8 @@ private:
RsEventsHandlerId_t mEventHandlerId; RsEventsHandlerId_t mEventHandlerId;
RsEventsHandlerId_t mTagEventHandlerId; RsEventsHandlerId_t mTagEventHandlerId;
FontSizeHandler mFontSizeHandler;
}; };
#endif #endif

View file

@ -93,6 +93,8 @@ SettingsPage::SettingsPage(QWidget *parent)
connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int))); connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int))); connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
mFontSizeHandler.registerFontSize(ui.listWidget);
} }
SettingsPage::~SettingsPage() SettingsPage::~SettingsPage()
@ -239,25 +241,3 @@ void SettingsPage::notifySettingsChanged()
if (NotifyQt::getInstance()) if (NotifyQt::getInstance())
NotifyQt::getInstance()->notifySettingsChanged(); NotifyQt::getInstance()->notifySettingsChanged();
} }
void SettingsPage::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void SettingsPage::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
#endif
QFont newFont = ui.listWidget->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
ui.listWidget->setFont(newFont);
}
}

View file

@ -27,6 +27,7 @@
#include <retroshare-gui/mainpage.h> #include <retroshare-gui/mainpage.h>
#include "ui_settingsw.h" #include "ui_settingsw.h"
#include "util/FontSizeHandler.h"
class FloatingHelpBrowser; class FloatingHelpBrowser;
@ -53,7 +54,6 @@ protected:
~SettingsPage(); ~SettingsPage();
void addPage(ConfigPage*) ; void addPage(ConfigPage*) ;
virtual void showEvent(QShowEvent *) override;
public slots: public slots:
//! Go to a specific part of the control panel. //! Go to a specific part of the control panel.
@ -68,12 +68,13 @@ private slots:
private: private:
void initStackedWidget(); void initStackedWidget();
void updateFontSize();
private: private:
FloatingHelpBrowser *mHelpBrowser; FloatingHelpBrowser *mHelpBrowser;
static int lastPage; static int lastPage;
FontSizeHandler mFontSizeHandler;
/* UI - from Designer */ /* UI - from Designer */
Ui::Settings ui; Ui::Settings ui;
}; };

View file

@ -167,7 +167,7 @@ RichTextEdit::RichTextEdit(QWidget *parent) : QWidget(parent) {
QFontDatabase db; QFontDatabase db;
foreach(int size, db.standardSizes()) foreach(int size, db.standardSizes())
f_fontsize->addItem(QString::number(size)); f_fontsize->addItem(QString::number(size), size);
connect(f_fontsize, SIGNAL(activated(QString)), connect(f_fontsize, SIGNAL(activated(QString)),
this, SLOT(textSize(QString))); this, SLOT(textSize(QString)));
@ -195,6 +195,9 @@ RichTextEdit::RichTextEdit(QWidget *parent) : QWidget(parent) {
// check message length // check message length
connect(f_textedit, SIGNAL(textChanged()), this, SLOT(checkLength())); connect(f_textedit, SIGNAL(textChanged()), this, SLOT(checkLength()));
mMessageFontSizeHandler.registerFontSize(f_textedit, [this] (QWidget*, int fontSize) {
f_fontsize->setCurrentIndex(f_fontsize->findData(fontSize));
});
} }
@ -614,26 +617,3 @@ void RichTextEdit::checkLength(){
void RichTextEdit::setPlaceHolderTextPosted() { void RichTextEdit::setPlaceHolderTextPosted() {
f_textedit->setPlaceholderText(tr("Text (optional)")); f_textedit->setPlaceholderText(tr("Text (optional)"));
} }
void RichTextEdit::showEvent(QShowEvent *event)
{
if (!event->spontaneous()) {
updateFontSize();
}
}
void RichTextEdit::updateFontSize()
{
#if defined(Q_OS_DARWIN)
int customFontSize = Settings->valueFromGroup("Messages", "MinimumFontSize", 13).toInt();
#else
int customFontSize = Settings->valueFromGroup("Messages", "MinimumFontSize", 12).toInt();
#endif
QFont newFont = f_textedit->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
f_textedit->setFont(newFont);
f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(newFont.pointSize())));
}
}

View file

@ -23,6 +23,7 @@
#include <QPointer> #include <QPointer>
#include "ui_RichTextEdit.h" #include "ui_RichTextEdit.h"
#include "util/FontSizeHandler.h"
/** /**
* @Brief A simple rich-text editor * @Brief A simple rich-text editor
@ -69,7 +70,6 @@ signals:
void insertImage(); void insertImage();
void textSource(); void textSource();
void checkLength(); void checkLength();
void updateFontSize();
protected: protected:
void mergeFormatOnWordOrSelection(const QTextCharFormat &format); void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
@ -79,7 +79,6 @@ signals:
void list(bool checked, QTextListFormat::Style style); void list(bool checked, QTextListFormat::Style style);
void indent(int delta); void indent(int delta);
void focusInEvent(QFocusEvent *event); void focusInEvent(QFocusEvent *event);
virtual void showEvent(QShowEvent *);
QStringList m_paragraphItems; QStringList m_paragraphItems;
int m_fontsize_h1; int m_fontsize_h1;
@ -95,6 +94,9 @@ signals:
ParagraphMonospace }; ParagraphMonospace };
QPointer<QTextList> m_lastBlockList; QPointer<QTextList> m_lastBlockList;
private:
MessageFontSizeHandler mMessageFontSizeHandler;
}; };
#endif #endif