=== modified file 'mixxx/src/widget/wpushbutton.cpp' --- mixxx/src/widget/wpushbutton.cpp 2011-10-16 02:09:36 +0000 +++ mixxx/src/widget/wpushbutton.cpp 2011-12-21 19:53:49 +0000 @@ -24,6 +24,7 @@ #include #include #include +#include WPushButton::WPushButton(QWidget * parent) : WWidget(parent) { @@ -50,6 +51,8 @@ int iNumStates = selectNodeInt(node, "NumberStates"); setStates(iNumStates); + m_powerWindowStyle = selectNodeQString(node, "PowerWindowStyle").contains("true", Qt::CaseInsensitive); + // Set background pixmap if available if (!selectNode(node, "BackPath").isNull()) setPixmapBackground(getPath(selectNodeQString(node, "BackPath"))); @@ -66,85 +69,21 @@ state = state.nextSibling(); } - m_bLeftClickForcePush = false; - if (selectNodeQString(node, "LeftClickIsPushButton").contains("true", Qt::CaseInsensitive)) + if (selectNodeQString(node, "LeftClickIsPushButton").contains("true", Qt::CaseInsensitive)) { m_bLeftClickForcePush = true; + } else { + m_bLeftClickForcePush = false; + } - m_bRightClickForcePush = false; - if (selectNodeQString(node, "RightClickIsPushButton").contains("true", Qt::CaseInsensitive)) + if (selectNodeQString(node, "RightClickIsPushButton").contains("true", Qt::CaseInsensitive)) { m_bRightClickForcePush = true; - - //-------- - //This next big block allows each ControlPushButton to know whether or not it's - //a "toggle" button. - - // For each connection - QDomNode con = selectNode(node, "Connection"); - while (!con.isNull()) - { - // Get ConfigKey - QString key = selectNodeQString(con, "ConfigKey"); - - ConfigKey configKey; - configKey.group = key.left(key.indexOf(",")); - configKey.item = key.mid(key.indexOf(",")+1); - - //Find out if we're a push button... - if (node.nodeName() == "PushButton") - { - ControlPushButton* p = dynamic_cast( - ControlObject::getControl(configKey)); - - if (p == NULL) { - // A NULL here either means that this control is not a - // ControlPushButton or it does not exist. This logic is - // specific to push-buttons, so skip it either way. - con = con.nextSibling(); - continue; - } - - bool isLeftButton = false; - bool isRightButton = false; - if (!selectNode(con, "ButtonState").isNull()) - { - if (selectNodeQString(con, "ButtonState").contains("LeftButton", Qt::CaseInsensitive)) { - isLeftButton = true; - } - else if (selectNodeQString(con, "ButtonState").contains("RightButton", Qt::CaseInsensitive)) { - isRightButton = true; - } - } - - // If we have 2 states, tell my controlpushbutton object that we're - // a toggle button. Only set the control as a toggle button if it - // has not been forced to remain a push button by the - // Right/LeftClickIsPushButton directive above. Do this by checking - // whether this control is mapped to the RightButton or LeftButton - // and check it against the value of m_bLeft/RightClickForcePush. We - // have to handle the case where no ButtonState is provided for the - // control. If no button is provided, then we have to assume the - // connected control should be a toggle. - - //bool setAsToggleButton = iNumStates == 2 && - // ((!isLeftButton && !isRightButton) || - // ( (isLeftButton && !m_bLeftClickForcePush) || - // (isRightButton && !m_bRightClickForcePush) ) ); - - // if (setAsToggleButton) - // p->setToggleButton(true); - - // BJW: Removed this so that buttons that are hardcoded as toggle in the source - // don't get overridden if a skin fails to set them to 2-state. Buttons still - // default to non-toggle otherwise. - // else - // p->setToggleButton(false); - } - - con = con.nextSibling(); + } else { + m_bRightClickForcePush = false; } - //End of toggle button stuff. - //-------- + // BJW: Removed toggle button detection so that buttons that are hardcoded as toggle in the source + // don't isLeftButtonget overridden if a skin fails to set them to 2-state. Buttons still + // default to non-toggle otherwise. } void WPushButton::setStates(int iStates) @@ -215,74 +154,100 @@ void WPushButton::mousePressEvent(QMouseEvent * e) { - m_bPressed = true; - - bool leftClick = e->button() == Qt::LeftButton; - bool rightClick = e->button() == Qt::RightButton; - - // The value to emit. - double emitValue = m_fValue; - - // Calculate new state if it is a one state button - if (m_iNoStates == 1) { - m_fValue = emitValue = (m_fValue == 0.0f) ? 1.0f : 0.0f; - } - // Update state on press if it is a n-state button and not a pushbutton - else if (leftClick) { + Qt::MouseButton klickButton = e->button(); + + if (m_powerWindowStyle && m_iNoStates == 2) { + if (klickButton == Qt::LeftButton) { + if (m_fValue == 0.0f) { + m_clickTimer.setSingleShot(true); + m_clickTimer.start(300); + } + m_fValue = 1.0f; + m_bPressed = true; + emit(valueChangedLeftDown(1.0f)); + update(); + } + return; + } + + if (klickButton == Qt::RightButton) { + // This is the secondary button function, it does not change m_fValue + // due the leak of visual feedback we do not allow a toggle function + if (m_bRightClickForcePush) { + m_bPressed = true; + emit(valueChangedRightDown(1.0f)); + update(); + } + return; + } + + if (klickButton == Qt::LeftButton) { + double emitValue; if (m_bLeftClickForcePush) { + // This may a button with different functions on each mouse button + // m_fValue is changed by a separate feedback connection emitValue = 1.0f; + } else if (m_iNoStates == 1) { + // This is a Pushbutton + m_fValue = emitValue = 1.0f; } else { + // Toggle thru the states m_fValue = emitValue = (int)(m_fValue+1.)%m_iNoStates; } - } - - // Do not allow right-clicks to change the state of the button. This is how - // Mixxx <1.8.0 worked so keep it that way. For a multi-state button, really - // only one click type (left/right) should be able to change the state. One - // problem with this is that you can get the button out of sync with its - // underlying control. For example the PFL buttons on Jus's skins could get - // out of sync with the button state. rryan 9/2010 - - // else if (rightClick) { - // if (m_bRightClickForcePush) { - // emitValue = 1.0f; - // } else { - // m_fValue = emitValue = (int)(m_fValue+1.)%m_iNoStates; - // } - // } - - if (leftClick) { + m_bPressed = true; emit(valueChangedLeftDown(emitValue)); - } else if (rightClick) { - emit(valueChangedRightDown(emitValue)); + update(); } - - update(); } void WPushButton::mouseReleaseEvent(QMouseEvent * e) { - m_bPressed = false; - - bool leftClick = e->button() == Qt::LeftButton; - bool rightClick = e->button() == Qt::RightButton; - - // The value to emit - double emitValue = m_fValue; - - // Update state if it is a one state button. - if (m_iNoStates==1) // && e->button()==Qt::LeftButton) - { - m_fValue = emitValue = (m_fValue == 0.0f) ? 1.0f : 0.0f; - } else if ((leftClick && m_bLeftClickForcePush) || (rightClick && m_bRightClickForcePush)) { - emitValue = 0.0f; - } - - if (leftClick) { - emit(valueChangedLeftUp(emitValue)); - } else if (rightClick) { - emit(valueChangedRightUp(emitValue)); - } - - update(); + Qt::MouseButton klickButton = e->button(); + + if (m_powerWindowStyle && m_iNoStates == 2) { + if (klickButton == Qt::LeftButton) { + if ( !m_clickTimer.isActive() + && !(QApplication::mouseButtons() & Qt::RightButton) + && m_bPressed) { + // Release Button after Timer, but not if right button is clicked + m_fValue = 0.0f; + emit(valueChangedLeftUp(0.0f)); + } + m_bPressed = false; + } + else if (klickButton == Qt::RightButton) { + m_bPressed = false; + } + update(); + return; + } + + if (klickButton == Qt::RightButton) { + // This is the secondary klickButton function, it does not change m_fValue + // due the leak of visual feedback we do not allow a toggle function + if (m_bRightClickForcePush) { + m_bPressed = false; + emit(valueChangedRightDown(0.0f)); + update(); + } + return; + } + + if (klickButton == Qt::LeftButton) { + double emitValue; + if (m_bLeftClickForcePush) { + // This may a klickButton with different functions on each mouse button + // m_fValue is changed by a separate feedback connection + emitValue = 0.0f; + } else if (m_iNoStates == 1) { + // This is a Pushbutton + m_fValue = emitValue = 0.0f; + } else { + // Nothing special happens when releasing a toggle button + emitValue = m_fValue; + } + m_bPressed = false; + emit(valueChangedLeftDown(emitValue)); + update(); + } } === modified file 'mixxx/src/widget/wpushbutton.h' --- mixxx/src/widget/wpushbutton.h 2010-09-14 06:32:04 +0000 +++ mixxx/src/widget/wpushbutton.h 2011-12-21 20:12:41 +0000 @@ -64,6 +64,9 @@ QPixmap **m_pPixmaps; /** Associated background pixmap */ QPixmap *m_pPixmapBack; + /** short click toggle button long click push button **/ + bool m_powerWindowStyle; + QTimer m_clickTimer; }; #endif