Skip to content

Commit

Permalink
Merge #906: [GUI] Move menu to cursor location instead of far right o…
Browse files Browse the repository at this point in the history
…f the rectangle

51bd07e -move to cursor location instead of far right of the rectangle -Adjustment for timeout and enter and leave mouse event -remove commented out code this took way too long fix for off-screen dropdown (Rock-N-Troll)

Pull request description:

  **Before:**
  ![image](https://user-images.githubusercontent.com/34344520/112564208-3b62f180-8db1-11eb-88ca-37ea1ff52649.png)

  **After:**
  ![image](https://user-images.githubusercontent.com/34344520/112563958-b7106e80-8db0-11eb-82f4-4955d45f89ef.png)

  Previous code moved the selection menu to the far top right of the screen.
  Instead, the  selection menu should intuitively be right next to where you click.

Tree-SHA512: b94a385c649ef01586c3d5d7af8798e41dbd829800fe4e136cc93d3bf3d47eae2721153f49e63d746e8b68d669876c01c84e3dacaebe781c39c74ebd58a16056
  • Loading branch information
codeofalltrades committed May 25, 2021
2 parents 15a0b61 + 51bd07e commit 2eb430d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/qt/veil/addressesmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ AddressesMenu::AddressesMenu(const QString _type, const QModelIndex &_index, QWi
mainWindow(_mainWindow),
index(_index),
type(_type),
model(_model)
model(_model),
timeoutTimer(0)

{
ui->setupUi(this);

timeoutTimer = new QTimer(this);
connect(timeoutTimer, SIGNAL(timeout()), this, SLOT(hide()));

connect(ui->btnCopy,SIGNAL(clicked()),this,SLOT(onBtnCopyAddressClicked()));
connect(ui->btnDelete,SIGNAL(clicked()),this,SLOT(onBtnDeleteAddressClicked()));
connect(ui->btnEdit,SIGNAL(clicked()),this,SLOT(onBtnEditAddressClicked()));
Expand Down Expand Up @@ -81,7 +86,15 @@ void AddressesMenu::setInitData(const QModelIndex &_index, AddressTableModel *_m
}

void AddressesMenu::showEvent(QShowEvent *event){
QTimer::singleShot(3500, this, SLOT(hide()));
timeoutTimer->start(3500);
}

void AddressesMenu::enterEvent(QEvent *event){
timeoutTimer->stop();
}

void AddressesMenu::leaveEvent(QEvent *event){
hide();
}

AddressesMenu::~AddressesMenu() {
Expand Down
5 changes: 4 additions & 1 deletion src/qt/veil/addressesmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class AddressesMenu : public QWidget
~AddressesMenu();

public Q_SLOTS:
virtual void showEvent(QShowEvent *event) override;
virtual void showEvent(QShowEvent *event) override;
virtual void enterEvent(QEvent *event) override;
virtual void leaveEvent(QEvent *event) override;

private Q_SLOTS:
void onBtnCopyAddressClicked();
Expand All @@ -48,6 +50,7 @@ private Q_SLOTS:
QModelIndex index;
QString type;
AddressTableModel *model;
QTimer *timeoutTimer;
};

#endif // ADDRESSESMENU_H
18 changes: 13 additions & 5 deletions src/qt/veil/addresseswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,25 @@ void AddressesWidget::handleAddressClicked(const QModelIndex &index){

listView->setCurrentIndex(updatedIndex);
QRect rect = listView->visualRect(index);
QPoint pos = rect.topRight();
pos.setX(pos.x() - (DECORATION_SIZE * 2));
pos.setY(pos.y() + (DECORATION_SIZE));

const QString constType = type;
if(!this->menu) this->menu = new AddressesMenu(constType , updatedIndex, this, this->mainWindow, this->model);
if(!this->menu) this->menu = new AddressesMenu(constType , updatedIndex, mainWindow->getGUI(), this->mainWindow, this->model);
else {
this->menu->hide();
this->menu->setInitData(updatedIndex, this->model, constType);
}

QPoint pos = mainWindow->getGUI()->mapFromGlobal(QCursor::pos());

if(pos.x()+menu->width()>mainWindow->getGUI()->width()){
pos.setX(pos.x() - menu->width());
}
if(pos.y()+menu->height()>mainWindow->getGUI()->height()){
pos.setY(pos.y() - menu->height());
}

menu->move(pos);
menu->show();
menu->raise();
}

void AddressesWidget::initAddressesView(){
Expand Down

0 comments on commit 2eb430d

Please sign in to comment.