Skip to content

Commit

Permalink
MenuOption: fix a bug that wouldn't allow the menu to move around mor…
Browse files Browse the repository at this point in the history
…e than 9 tools

Signed-off-by: Daniel Guramulta <[email protected]>
  • Loading branch information
DanielGuramulta committed Mar 8, 2018
1 parent fc37e14 commit ca00c9a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/dragzone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void DragZone::dropEvent(QDropEvent *event)
}
}

int DragZone::getPosition() const
{
return position;
}

void DragZone::setPosition(int value)
{
position = value;
}

bool DragZone::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::DragEnter){
Expand Down
3 changes: 3 additions & 0 deletions src/dragzone.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class DragZone : public QWidget

bool eventFilter(QObject *watched, QEvent *event);

int getPosition() const;
void setPosition(int value);

Q_SIGNALS:
void requestPositionChange(int, int, bool);
void highlightLastSeparator(bool);
Expand Down
12 changes: 8 additions & 4 deletions src/menuoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ MenuOption::MenuOption(QString toolName, QString iconPath,
usesCustomBtn(usesCustomBtn),
botSep(nullptr),
topSep(nullptr),
detached(false)
detached(false),
maxMenuElements(8)
{
ui->setupUi(this);
ui->toolBtn->setText(toolName);
Expand Down Expand Up @@ -60,7 +61,7 @@ MenuOption::MenuOption(QString toolName, QString iconPath,
topSep->setSizePolicy(sp_retainTopSep);
topSep->setVisible(false);

if (position == 8){
if (position == maxMenuElements){
botSep = new QFrame(this);
botSep->setFrameShadow(QFrame::Plain);
botSep->setLineWidth(1);
Expand Down Expand Up @@ -96,7 +97,7 @@ QPushButton *MenuOption::getToolStopBtn()
void MenuOption::setPosition(int position)
{
this->position = position;
if (position != 8){
if (position != maxMenuElements){
if (botSep != nullptr){
ui->verticalLayout->removeWidget(botSep);
delete botSep;
Expand Down Expand Up @@ -140,6 +141,9 @@ bool MenuOption::isDetached()

void MenuOption::highlightBotSeparator(bool on)
{
if (!botSep)
return;

botSep->setVisible(on);
}

Expand Down Expand Up @@ -221,7 +225,7 @@ void MenuOption::dragMoveEvent(QDragMoveEvent *event)
highlightTopSeparator();
event->accept();
} else if (event->answerRect().intersects(botDragbox) &&
this->position == 8){
this->position == maxMenuElements){
disableSeparatorsHighlight();
highlightBotSeparator();
event->accept();
Expand Down
5 changes: 5 additions & 0 deletions src/menuoption.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ class MenuOption : public QWidget

void paintEvent(QPaintEvent *pe);
bool eventFilter(QObject *watched, QEvent *event);

int getMaxMenuElements() const;
void setMaxMenuElements(int value);

private:

bool detached;
int position;
QString toolName;
int maxMenuElements;

QPoint dragStartPosition;

Expand Down
21 changes: 18 additions & 3 deletions src/tool_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,23 @@ void ToolLauncher::generateMenu()
}

void ToolLauncher::insertMenuOptions(){

if (debugger_enabled) {
for (auto &option : toolMenu) {
option->setMaxMenuElements(
option->getMaxMenuElements() + 1);
}
}

int offset = 0;
for (int i = 0; i < position.size(); ++i){
ui->menuOptionsLayout->insertWidget(i, toolMenu[tools[position[i]]]);
toolMenu[tools[position[i]]]->setPosition(i);
if (toolMenu[tools[position[i]]]->getName() == "Debugger"
&& !debugger_enabled) {
offset = 1;
continue;
}
ui->menuOptionsLayout->insertWidget(i - offset, toolMenu[tools[position[i]]]);
toolMenu[tools[position[i]]]->setPosition(i - offset);
ui->buttonGroup_2->addButton(toolMenu[tools[position[i]]]->getToolBtn());
}

Expand All @@ -484,6 +498,7 @@ void ToolLauncher::insertMenuOptions(){
SLOT(highlightLast(bool)));

toolMenu["Debugger"]->setVisible(debugger_enabled);
dragZone->setPosition(ui->menuOptionsLayout->count() - 2);
}

void ToolLauncher::highlightLast(bool on){
Expand Down Expand Up @@ -1362,7 +1377,7 @@ void ToolLauncher::closeEvent(QCloseEvent *event)

void ToolLauncher::swapMenuOptions(int source, int destination, bool dropAfter)
{
int menuSize = ui->menuOptionsLayout->count();
int menuSize = toolMenu["Digital IO"]->getMaxMenuElements() + 1;

QWidget *sourceWidget = ui->menuOptionsLayout->itemAt(source)->widget();
if (dropAfter == true){
Expand Down

0 comments on commit ca00c9a

Please sign in to comment.