Commit 1c20ef15 authored by Isa's avatar Isa Committed by Andreas Traczyk

account: update combobox when adding accounts

Change-Id: I2952252bdb3f732ccc0074d053780e1a5648087f
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent f9f7eed1
......@@ -97,7 +97,6 @@ CallWidget::CallWidget(QWidget* parent) :
auto index = Utils::indexInVector(accountList, accountIdToStartWith);
if (index != -1) {
ui->currentAccountComboBox->setCurrentIndex(index);
ui->currentAccountComboBox->importLabelPhoto(index);
}
}
......
......@@ -36,15 +36,14 @@ CurrentAccountComboBox::CurrentAccountComboBox(QWidget* parent)
{
Q_UNUSED(parent);
accountListModel_ = std::make_unique<AccountListModel>();
this->setModel(accountListModel_.get());
accountListUpdate();
accountItemDelegate_ = new AccountItemDelegate();
this->setItemDelegate(accountItemDelegate_);
// combobox index changed and so must the avatar
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged),
[=](const int& index) {
importLabelPhoto(index);
setCurrentIndex(index);
});
// account added to combobox
......@@ -71,7 +70,7 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
QPoint p(2, 2);
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing, QPainter::TextAntialiasing);
painter.setRenderHints((QPainter::Antialiasing | QPainter::TextAntialiasing), true);
QStyleOption opt;
opt.init(this);
......@@ -79,8 +78,7 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
// create box in which to draw avatar and presence indicator
QRect avatarRect(2, 2, cellHeight_, cellHeight_); // [screen awareness]
QRect comboBoxRect(52, 2, 322, cellHeight_-4); // [screen awareness]
QRect comboBoxRect(cellHeight_ + p.x() + 2, 4, this->width() - cellHeight_ + p.x(), cellHeight_- 10); // [screen awareness]
// define and set the two fonts
QFont fontPrimary = painter.font();
......@@ -111,7 +109,7 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
}
// write primary and secondary account identifiers to combobox label
const int elidConst = 85; // [screen awareness]
const int elidConst = 80; // [screen awareness]
QString primaryAccountID = QString::fromStdString(Utils::bestNameForAccount(LRCInstance::getCurrentAccountInfo()));
painter.setPen(Qt::black);
......@@ -138,8 +136,22 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
// import account background account pixmap and scale pixmap to fit in label
void
CurrentAccountComboBox::importLabelPhoto(const int& index)
CurrentAccountComboBox::importLabelPhoto(int index)
{
currentAccountAvatarImage_ = accountListModel_->data(accountListModel_->index(index), // [efficiency improvement]
currentAccountAvatarImage_ = accountListModel_->data(accountListModel_->index(index, 0), // [efficiency improvement]
AccountListModel::Role::Picture).value<QPixmap>().scaledToHeight(cellHeight_ - 4, Qt::SmoothTransformation);
}
\ No newline at end of file
}
void
CurrentAccountComboBox::setCurrentIndex(int index)
{
importLabelPhoto(index);
QComboBox::setCurrentIndex(index);
}
void
CurrentAccountComboBox::accountListUpdate()
{
accountListModel_.reset(new AccountListModel());
this->setModel(accountListModel_.get());
}
......@@ -28,15 +28,18 @@ namespace Ui {
class CurrentAccountComboBox : public QComboBox
{
Q_OBJECT
CurrentAccountComboBox(const CurrentAccountComboBox& cpy);
CurrentAccountComboBox(const CurrentAccountComboBox& cpy);
public:
explicit CurrentAccountComboBox(QWidget* parent = nullptr);
~CurrentAccountComboBox();
void importLabelPhoto(const int& index);
void accountListUpdate();
void setCurrentIndex(int index);
private:
void paintEvent(QPaintEvent* e);
void importLabelPhoto(int index);
AccountItemDelegate* accountItemDelegate_;
std::unique_ptr<AccountListModel> accountListModel_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment