Changed clang format to new agreement
This commit is contained in:
committed by
borgmanJeremy
parent
2cbccc3d0a
commit
0d5386edd4
@@ -28,386 +28,374 @@ ButtonHandler::ButtonHandler(const QVector<CaptureToolButton*>& v,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
setButtons(v);
|
||||
init();
|
||||
setButtons(v);
|
||||
init();
|
||||
}
|
||||
|
||||
ButtonHandler::ButtonHandler(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::hide()
|
||||
void ButtonHandler::hide()
|
||||
{
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
b->hide();
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
b->hide();
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::show()
|
||||
void ButtonHandler::show()
|
||||
{
|
||||
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
|
||||
return;
|
||||
}
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
b->animatedShow();
|
||||
}
|
||||
|
||||
bool
|
||||
ButtonHandler::isVisible() const
|
||||
{
|
||||
bool ret = true;
|
||||
for (const CaptureToolButton* b : m_vectorButtons) {
|
||||
if (!b->isVisible()) {
|
||||
ret = false;
|
||||
break;
|
||||
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
b->animatedShow();
|
||||
}
|
||||
|
||||
bool
|
||||
ButtonHandler::buttonsAreInside() const
|
||||
bool ButtonHandler::isVisible() const
|
||||
{
|
||||
return m_buttonsAreInside;
|
||||
bool ret = true;
|
||||
for (const CaptureToolButton* b : m_vectorButtons) {
|
||||
if (!b->isVisible()) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
ButtonHandler::size() const
|
||||
bool ButtonHandler::buttonsAreInside() const
|
||||
{
|
||||
return m_vectorButtons.size();
|
||||
return m_buttonsAreInside;
|
||||
}
|
||||
|
||||
size_t ButtonHandler::size() const
|
||||
{
|
||||
return m_vectorButtons.size();
|
||||
}
|
||||
|
||||
// updatePosition updates the position of the buttons around the
|
||||
// selection area. Ignores the sides blocked by the end of the screen.
|
||||
// When the selection is too small it works on a virtual selection with
|
||||
// the original in the center.
|
||||
void
|
||||
ButtonHandler::updatePosition(const QRect& selection)
|
||||
void ButtonHandler::updatePosition(const QRect& selection)
|
||||
{
|
||||
resetRegionTrack();
|
||||
const int vecLength = m_vectorButtons.size();
|
||||
if (vecLength == 0) {
|
||||
return;
|
||||
}
|
||||
// Copy of the selection area for internal modifications
|
||||
m_selection = intersectWithAreas(selection);
|
||||
updateBlockedSides();
|
||||
ensureSelectionMinimunSize();
|
||||
// Indicates the actual button to be moved
|
||||
int elemIndicator = 0;
|
||||
|
||||
while (elemIndicator < vecLength) {
|
||||
|
||||
// Add them inside the area when there is no more space
|
||||
if (m_allSidesBlocked) {
|
||||
m_selection = selection;
|
||||
positionButtonsInside(elemIndicator);
|
||||
break; // the while
|
||||
}
|
||||
// Number of buttons per row column
|
||||
int buttonsPerRow =
|
||||
(m_selection.width() + m_separator) / (m_buttonExtendedSize);
|
||||
int buttonsPerCol =
|
||||
(m_selection.height() + m_separator) / (m_buttonExtendedSize);
|
||||
// Buttons to be placed in the corners
|
||||
int extraButtons =
|
||||
(vecLength - elemIndicator) - (buttonsPerRow + buttonsPerCol) * 2;
|
||||
int elemsAtCorners = extraButtons > 4 ? 4 : extraButtons;
|
||||
int maxExtra = 2;
|
||||
if (m_oneHorizontalBlocked) {
|
||||
maxExtra = 1;
|
||||
} else if (m_horizontalyBlocked) {
|
||||
maxExtra = 0;
|
||||
}
|
||||
int elemCornersTop = qBound(0, elemsAtCorners, maxExtra);
|
||||
elemsAtCorners -= elemCornersTop;
|
||||
int elemCornersBotton = qBound(0, elemsAtCorners, maxExtra);
|
||||
|
||||
// Add buttons at the button of the seletion
|
||||
if (!m_blockedBotton) {
|
||||
int addCounter = buttonsPerRow + elemCornersBotton;
|
||||
// Don't add more than we have
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
QPoint center =
|
||||
QPoint(m_selection.center().x(), m_selection.bottom() + m_separator);
|
||||
if (addCounter > buttonsPerRow) {
|
||||
adjustHorizontalCenter(center);
|
||||
}
|
||||
// ElemIndicator, elemsAtCorners
|
||||
QVector<QPoint> positions = horizontalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the right side of the seletion
|
||||
if (!m_blockedRight && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerCol;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
|
||||
QPoint center =
|
||||
QPoint(m_selection.right() + m_separator, m_selection.center().y());
|
||||
QVector<QPoint> positions = verticalPoints(center, addCounter, false);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the top of the seletion
|
||||
if (!m_blockedTop && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerRow + elemCornersTop;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
QPoint center = QPoint(m_selection.center().x(),
|
||||
m_selection.top() - m_buttonExtendedSize);
|
||||
if (addCounter == 1 + buttonsPerRow) {
|
||||
adjustHorizontalCenter(center);
|
||||
}
|
||||
QVector<QPoint> positions = horizontalPoints(center, addCounter, false);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the left side of the seletion
|
||||
if (!m_blockedLeft && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerCol;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
|
||||
QPoint center = QPoint(m_selection.left() - m_buttonExtendedSize,
|
||||
m_selection.center().y());
|
||||
QVector<QPoint> positions = verticalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// If there are elements for the next cycle, increase the size of the
|
||||
// base area
|
||||
if (elemIndicator < vecLength && !(m_allSidesBlocked)) {
|
||||
expandSelection();
|
||||
resetRegionTrack();
|
||||
const int vecLength = m_vectorButtons.size();
|
||||
if (vecLength == 0) {
|
||||
return;
|
||||
}
|
||||
// Copy of the selection area for internal modifications
|
||||
m_selection = intersectWithAreas(selection);
|
||||
updateBlockedSides();
|
||||
}
|
||||
ensureSelectionMinimunSize();
|
||||
// Indicates the actual button to be moved
|
||||
int elemIndicator = 0;
|
||||
|
||||
while (elemIndicator < vecLength) {
|
||||
|
||||
// Add them inside the area when there is no more space
|
||||
if (m_allSidesBlocked) {
|
||||
m_selection = selection;
|
||||
positionButtonsInside(elemIndicator);
|
||||
break; // the while
|
||||
}
|
||||
// Number of buttons per row column
|
||||
int buttonsPerRow =
|
||||
(m_selection.width() + m_separator) / (m_buttonExtendedSize);
|
||||
int buttonsPerCol =
|
||||
(m_selection.height() + m_separator) / (m_buttonExtendedSize);
|
||||
// Buttons to be placed in the corners
|
||||
int extraButtons =
|
||||
(vecLength - elemIndicator) - (buttonsPerRow + buttonsPerCol) * 2;
|
||||
int elemsAtCorners = extraButtons > 4 ? 4 : extraButtons;
|
||||
int maxExtra = 2;
|
||||
if (m_oneHorizontalBlocked) {
|
||||
maxExtra = 1;
|
||||
} else if (m_horizontalyBlocked) {
|
||||
maxExtra = 0;
|
||||
}
|
||||
int elemCornersTop = qBound(0, elemsAtCorners, maxExtra);
|
||||
elemsAtCorners -= elemCornersTop;
|
||||
int elemCornersBotton = qBound(0, elemsAtCorners, maxExtra);
|
||||
|
||||
// Add buttons at the button of the seletion
|
||||
if (!m_blockedBotton) {
|
||||
int addCounter = buttonsPerRow + elemCornersBotton;
|
||||
// Don't add more than we have
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
QPoint center = QPoint(m_selection.center().x(),
|
||||
m_selection.bottom() + m_separator);
|
||||
if (addCounter > buttonsPerRow) {
|
||||
adjustHorizontalCenter(center);
|
||||
}
|
||||
// ElemIndicator, elemsAtCorners
|
||||
QVector<QPoint> positions =
|
||||
horizontalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the right side of the seletion
|
||||
if (!m_blockedRight && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerCol;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
|
||||
QPoint center = QPoint(m_selection.right() + m_separator,
|
||||
m_selection.center().y());
|
||||
QVector<QPoint> positions =
|
||||
verticalPoints(center, addCounter, false);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the top of the seletion
|
||||
if (!m_blockedTop && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerRow + elemCornersTop;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
QPoint center = QPoint(m_selection.center().x(),
|
||||
m_selection.top() - m_buttonExtendedSize);
|
||||
if (addCounter == 1 + buttonsPerRow) {
|
||||
adjustHorizontalCenter(center);
|
||||
}
|
||||
QVector<QPoint> positions =
|
||||
horizontalPoints(center, addCounter, false);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// Add buttons at the left side of the seletion
|
||||
if (!m_blockedLeft && elemIndicator < vecLength) {
|
||||
int addCounter = buttonsPerCol;
|
||||
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
|
||||
|
||||
QPoint center = QPoint(m_selection.left() - m_buttonExtendedSize,
|
||||
m_selection.center().y());
|
||||
QVector<QPoint> positions =
|
||||
verticalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, elemIndicator);
|
||||
}
|
||||
// If there are elements for the next cycle, increase the size of the
|
||||
// base area
|
||||
if (elemIndicator < vecLength && !(m_allSidesBlocked)) {
|
||||
expandSelection();
|
||||
}
|
||||
updateBlockedSides();
|
||||
}
|
||||
}
|
||||
|
||||
// horizontalPoints is an auxiliary method for the button position computation.
|
||||
// starts from a known center and keeps adding elements horizontally
|
||||
// and returns the computed positions.
|
||||
QVector<QPoint>
|
||||
ButtonHandler::horizontalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool leftToRight) const
|
||||
QVector<QPoint> ButtonHandler::horizontalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool leftToRight) const
|
||||
{
|
||||
QVector<QPoint> res;
|
||||
// Distance from the center to start adding buttons
|
||||
int shift = 0;
|
||||
if (elements % 2 == 0) {
|
||||
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
|
||||
} else {
|
||||
shift = m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
|
||||
}
|
||||
if (!leftToRight) {
|
||||
shift -= m_buttonBaseSize;
|
||||
}
|
||||
int x = leftToRight ? center.x() - shift : center.x() + shift;
|
||||
QPoint i(x, center.y());
|
||||
while (elements > res.length()) {
|
||||
res.append(i);
|
||||
leftToRight ? i.setX(i.x() + m_buttonExtendedSize)
|
||||
: i.setX(i.x() - m_buttonExtendedSize);
|
||||
}
|
||||
return res;
|
||||
QVector<QPoint> res;
|
||||
// Distance from the center to start adding buttons
|
||||
int shift = 0;
|
||||
if (elements % 2 == 0) {
|
||||
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
|
||||
} else {
|
||||
shift =
|
||||
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
|
||||
}
|
||||
if (!leftToRight) {
|
||||
shift -= m_buttonBaseSize;
|
||||
}
|
||||
int x = leftToRight ? center.x() - shift : center.x() + shift;
|
||||
QPoint i(x, center.y());
|
||||
while (elements > res.length()) {
|
||||
res.append(i);
|
||||
leftToRight ? i.setX(i.x() + m_buttonExtendedSize)
|
||||
: i.setX(i.x() - m_buttonExtendedSize);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// verticalPoints is an auxiliary method for the button position computation.
|
||||
// starts from a known center and keeps adding elements vertically
|
||||
// and returns the computed positions.
|
||||
QVector<QPoint>
|
||||
ButtonHandler::verticalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool upToDown) const
|
||||
QVector<QPoint> ButtonHandler::verticalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool upToDown) const
|
||||
{
|
||||
QVector<QPoint> res;
|
||||
// Distance from the center to start adding buttons
|
||||
int shift = 0;
|
||||
if (elements % 2 == 0) {
|
||||
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
|
||||
} else {
|
||||
shift = m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
|
||||
}
|
||||
if (!upToDown) {
|
||||
shift -= m_buttonBaseSize;
|
||||
}
|
||||
int y = upToDown ? center.y() - shift : center.y() + shift;
|
||||
QPoint i(center.x(), y);
|
||||
while (elements > res.length()) {
|
||||
res.append(i);
|
||||
upToDown ? i.setY(i.y() + m_buttonExtendedSize)
|
||||
: i.setY(i.y() - m_buttonExtendedSize);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QRect
|
||||
ButtonHandler::intersectWithAreas(const QRect& rect)
|
||||
{
|
||||
QRect res;
|
||||
for (const QRect& r : m_screenRegions) {
|
||||
QRect temp = rect.intersected(r);
|
||||
if (temp.height() * temp.width() > res.height() * res.width()) {
|
||||
res = temp;
|
||||
QVector<QPoint> res;
|
||||
// Distance from the center to start adding buttons
|
||||
int shift = 0;
|
||||
if (elements % 2 == 0) {
|
||||
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
|
||||
} else {
|
||||
shift =
|
||||
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::init()
|
||||
{
|
||||
m_separator = GlobalValues::buttonBaseSize() / 4;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::resetRegionTrack()
|
||||
{
|
||||
m_buttonsAreInside = false;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::updateBlockedSides()
|
||||
{
|
||||
const int EXTENSION = m_separator * 2 + m_buttonBaseSize;
|
||||
// Right
|
||||
QPoint pointA(m_selection.right() + EXTENSION, m_selection.bottom());
|
||||
QPoint pointB(pointA.x(), m_selection.top());
|
||||
m_blockedRight =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Left
|
||||
pointA.setX(m_selection.left() - EXTENSION);
|
||||
pointB.setX(pointA.x());
|
||||
m_blockedLeft =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Bottom
|
||||
pointA = QPoint(m_selection.left(), m_selection.bottom() + EXTENSION);
|
||||
pointB = QPoint(m_selection.right(), pointA.y());
|
||||
m_blockedBotton =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Top
|
||||
pointA.setY(m_selection.top() - EXTENSION);
|
||||
pointB.setY(pointA.y());
|
||||
m_blockedTop =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Auxiliary
|
||||
m_oneHorizontalBlocked =
|
||||
(!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft);
|
||||
m_horizontalyBlocked = (m_blockedRight && m_blockedLeft);
|
||||
m_allSidesBlocked = (m_blockedBotton && m_horizontalyBlocked && m_blockedTop);
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::expandSelection()
|
||||
{
|
||||
int& s = m_buttonExtendedSize;
|
||||
m_selection = m_selection + QMargins(s, s, s, s);
|
||||
m_selection = intersectWithAreas(m_selection);
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::positionButtonsInside(int index)
|
||||
{
|
||||
// Position the buttons in the botton-center of the main but inside of the
|
||||
// selection.
|
||||
QRect mainArea = m_selection;
|
||||
mainArea = intersectWithAreas(mainArea);
|
||||
const int buttonsPerRow = (mainArea.width()) / (m_buttonExtendedSize);
|
||||
if (buttonsPerRow == 0) {
|
||||
return;
|
||||
}
|
||||
QPoint center =
|
||||
QPoint(mainArea.center().x(), mainArea.bottom() - m_buttonExtendedSize);
|
||||
|
||||
while (m_vectorButtons.size() > index) {
|
||||
int addCounter = buttonsPerRow;
|
||||
addCounter = qBound(0, addCounter, m_vectorButtons.size() - index);
|
||||
QVector<QPoint> positions = horizontalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, index);
|
||||
center.setY(center.y() - m_buttonExtendedSize);
|
||||
}
|
||||
|
||||
m_buttonsAreInside = true;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::ensureSelectionMinimunSize()
|
||||
{
|
||||
// Detect if a side is smaller than a button in order to prevent collision
|
||||
// and redimension the base area the the base size of a single button per side
|
||||
if (m_selection.width() < m_buttonBaseSize) {
|
||||
if (!m_blockedLeft) {
|
||||
m_selection.setX(m_selection.x() -
|
||||
(m_buttonBaseSize - m_selection.width()) / 2);
|
||||
if (!upToDown) {
|
||||
shift -= m_buttonBaseSize;
|
||||
}
|
||||
m_selection.setWidth(m_buttonBaseSize);
|
||||
}
|
||||
if (m_selection.height() < m_buttonBaseSize) {
|
||||
if (!m_blockedTop) {
|
||||
m_selection.setY(m_selection.y() -
|
||||
(m_buttonBaseSize - m_selection.height()) / 2);
|
||||
int y = upToDown ? center.y() - shift : center.y() + shift;
|
||||
QPoint i(center.x(), y);
|
||||
while (elements > res.length()) {
|
||||
res.append(i);
|
||||
upToDown ? i.setY(i.y() + m_buttonExtendedSize)
|
||||
: i.setY(i.y() - m_buttonExtendedSize);
|
||||
}
|
||||
m_selection.setHeight(m_buttonBaseSize);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points, int& index)
|
||||
QRect ButtonHandler::intersectWithAreas(const QRect& rect)
|
||||
{
|
||||
for (const QPoint& p : points) {
|
||||
auto button = m_vectorButtons[index];
|
||||
button->move(p);
|
||||
++index;
|
||||
}
|
||||
QRect res;
|
||||
for (const QRect& r : m_screenRegions) {
|
||||
QRect temp = rect.intersected(r);
|
||||
if (temp.height() * temp.width() > res.height() * res.width()) {
|
||||
res = temp;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::adjustHorizontalCenter(QPoint& center)
|
||||
void ButtonHandler::init()
|
||||
{
|
||||
if (m_blockedLeft) {
|
||||
center.setX(center.x() + m_buttonExtendedSize / 2);
|
||||
} else if (m_blockedRight) {
|
||||
center.setX(center.x() - m_buttonExtendedSize / 2);
|
||||
}
|
||||
m_separator = GlobalValues::buttonBaseSize() / 4;
|
||||
}
|
||||
|
||||
void ButtonHandler::resetRegionTrack()
|
||||
{
|
||||
m_buttonsAreInside = false;
|
||||
}
|
||||
|
||||
void ButtonHandler::updateBlockedSides()
|
||||
{
|
||||
const int EXTENSION = m_separator * 2 + m_buttonBaseSize;
|
||||
// Right
|
||||
QPoint pointA(m_selection.right() + EXTENSION, m_selection.bottom());
|
||||
QPoint pointB(pointA.x(), m_selection.top());
|
||||
m_blockedRight =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Left
|
||||
pointA.setX(m_selection.left() - EXTENSION);
|
||||
pointB.setX(pointA.x());
|
||||
m_blockedLeft =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Bottom
|
||||
pointA = QPoint(m_selection.left(), m_selection.bottom() + EXTENSION);
|
||||
pointB = QPoint(m_selection.right(), pointA.y());
|
||||
m_blockedBotton =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Top
|
||||
pointA.setY(m_selection.top() - EXTENSION);
|
||||
pointB.setY(pointA.y());
|
||||
m_blockedTop =
|
||||
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
|
||||
// Auxiliary
|
||||
m_oneHorizontalBlocked =
|
||||
(!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft);
|
||||
m_horizontalyBlocked = (m_blockedRight && m_blockedLeft);
|
||||
m_allSidesBlocked =
|
||||
(m_blockedBotton && m_horizontalyBlocked && m_blockedTop);
|
||||
}
|
||||
|
||||
void ButtonHandler::expandSelection()
|
||||
{
|
||||
int& s = m_buttonExtendedSize;
|
||||
m_selection = m_selection + QMargins(s, s, s, s);
|
||||
m_selection = intersectWithAreas(m_selection);
|
||||
}
|
||||
|
||||
void ButtonHandler::positionButtonsInside(int index)
|
||||
{
|
||||
// Position the buttons in the botton-center of the main but inside of the
|
||||
// selection.
|
||||
QRect mainArea = m_selection;
|
||||
mainArea = intersectWithAreas(mainArea);
|
||||
const int buttonsPerRow = (mainArea.width()) / (m_buttonExtendedSize);
|
||||
if (buttonsPerRow == 0) {
|
||||
return;
|
||||
}
|
||||
QPoint center =
|
||||
QPoint(mainArea.center().x(), mainArea.bottom() - m_buttonExtendedSize);
|
||||
|
||||
while (m_vectorButtons.size() > index) {
|
||||
int addCounter = buttonsPerRow;
|
||||
addCounter = qBound(0, addCounter, m_vectorButtons.size() - index);
|
||||
QVector<QPoint> positions = horizontalPoints(center, addCounter, true);
|
||||
moveButtonsToPoints(positions, index);
|
||||
center.setY(center.y() - m_buttonExtendedSize);
|
||||
}
|
||||
|
||||
m_buttonsAreInside = true;
|
||||
}
|
||||
|
||||
void ButtonHandler::ensureSelectionMinimunSize()
|
||||
{
|
||||
// Detect if a side is smaller than a button in order to prevent collision
|
||||
// and redimension the base area the the base size of a single button per
|
||||
// side
|
||||
if (m_selection.width() < m_buttonBaseSize) {
|
||||
if (!m_blockedLeft) {
|
||||
m_selection.setX(m_selection.x() -
|
||||
(m_buttonBaseSize - m_selection.width()) / 2);
|
||||
}
|
||||
m_selection.setWidth(m_buttonBaseSize);
|
||||
}
|
||||
if (m_selection.height() < m_buttonBaseSize) {
|
||||
if (!m_blockedTop) {
|
||||
m_selection.setY(m_selection.y() -
|
||||
(m_buttonBaseSize - m_selection.height()) / 2);
|
||||
}
|
||||
m_selection.setHeight(m_buttonBaseSize);
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points,
|
||||
int& index)
|
||||
{
|
||||
for (const QPoint& p : points) {
|
||||
auto button = m_vectorButtons[index];
|
||||
button->move(p);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonHandler::adjustHorizontalCenter(QPoint& center)
|
||||
{
|
||||
if (m_blockedLeft) {
|
||||
center.setX(center.x() + m_buttonExtendedSize / 2);
|
||||
} else if (m_blockedRight) {
|
||||
center.setX(center.x() - m_buttonExtendedSize / 2);
|
||||
}
|
||||
}
|
||||
|
||||
// setButtons redefines the buttons of the button handler
|
||||
void
|
||||
ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
|
||||
void ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
|
||||
{
|
||||
if (v.isEmpty())
|
||||
return;
|
||||
if (v.isEmpty())
|
||||
return;
|
||||
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
delete (b);
|
||||
m_vectorButtons = v;
|
||||
m_buttonBaseSize = GlobalValues::buttonBaseSize();
|
||||
m_buttonExtendedSize = m_buttonBaseSize + m_separator;
|
||||
for (CaptureToolButton* b : m_vectorButtons)
|
||||
delete (b);
|
||||
m_vectorButtons = v;
|
||||
m_buttonBaseSize = GlobalValues::buttonBaseSize();
|
||||
m_buttonExtendedSize = m_buttonBaseSize + m_separator;
|
||||
}
|
||||
|
||||
bool
|
||||
ButtonHandler::contains(const QPoint& p) const
|
||||
bool ButtonHandler::contains(const QPoint& p) const
|
||||
{
|
||||
QPoint first(m_vectorButtons.first()->pos());
|
||||
QPoint last(m_vectorButtons.last()->pos());
|
||||
bool firstIsTopLeft = (first.x() <= last.x() && first.y() <= last.y());
|
||||
QPoint topLeft = firstIsTopLeft ? first : last;
|
||||
QPoint bottonRight = firstIsTopLeft ? last : first;
|
||||
topLeft += QPoint(-m_separator, -m_separator);
|
||||
bottonRight += QPoint(m_buttonExtendedSize, m_buttonExtendedSize);
|
||||
QRegion r(QRect(topLeft, bottonRight).normalized());
|
||||
return r.contains(p);
|
||||
QPoint first(m_vectorButtons.first()->pos());
|
||||
QPoint last(m_vectorButtons.last()->pos());
|
||||
bool firstIsTopLeft = (first.x() <= last.x() && first.y() <= last.y());
|
||||
QPoint topLeft = firstIsTopLeft ? first : last;
|
||||
QPoint bottonRight = firstIsTopLeft ? last : first;
|
||||
topLeft += QPoint(-m_separator, -m_separator);
|
||||
bottonRight += QPoint(m_buttonExtendedSize, m_buttonExtendedSize);
|
||||
QRegion r(QRect(topLeft, bottonRight).normalized());
|
||||
return r.contains(p);
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
|
||||
void ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
|
||||
{
|
||||
m_screenRegions = QRegion();
|
||||
for (const QRect& rect : rects) {
|
||||
m_screenRegions += rect;
|
||||
}
|
||||
m_screenRegions = QRegion();
|
||||
for (const QRect& rect : rects) {
|
||||
m_screenRegions += rect;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ButtonHandler::updateScreenRegions(const QRect& rect)
|
||||
void ButtonHandler::updateScreenRegions(const QRect& rect)
|
||||
{
|
||||
m_screenRegions = QRegion(rect);
|
||||
m_screenRegions = QRegion(rect);
|
||||
}
|
||||
|
||||
@@ -28,63 +28,64 @@ class QPoint;
|
||||
|
||||
class ButtonHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ButtonHandler(const QVector<CaptureToolButton*>&, QObject* parent = nullptr);
|
||||
explicit ButtonHandler(QObject* parent = nullptr);
|
||||
ButtonHandler(const QVector<CaptureToolButton*>&,
|
||||
QObject* parent = nullptr);
|
||||
explicit ButtonHandler(QObject* parent = nullptr);
|
||||
|
||||
void hideSectionUnderMouse(const QPoint& p);
|
||||
void hideSectionUnderMouse(const QPoint& p);
|
||||
|
||||
bool isVisible() const;
|
||||
bool buttonsAreInside() const;
|
||||
size_t size() const;
|
||||
bool isVisible() const;
|
||||
bool buttonsAreInside() const;
|
||||
size_t size() const;
|
||||
|
||||
void setButtons(const QVector<CaptureToolButton*>);
|
||||
bool contains(const QPoint& p) const;
|
||||
void updateScreenRegions(const QVector<QRect>& rects);
|
||||
void updateScreenRegions(const QRect& rect);
|
||||
void setButtons(const QVector<CaptureToolButton*>);
|
||||
bool contains(const QPoint& p) const;
|
||||
void updateScreenRegions(const QVector<QRect>& rects);
|
||||
void updateScreenRegions(const QRect& rect);
|
||||
|
||||
public slots:
|
||||
void updatePosition(const QRect& selection);
|
||||
void hide();
|
||||
void show();
|
||||
void updatePosition(const QRect& selection);
|
||||
void hide();
|
||||
void show();
|
||||
|
||||
private:
|
||||
QVector<QPoint> horizontalPoints(const QPoint& center,
|
||||
QVector<QPoint> horizontalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool leftToRight) const;
|
||||
QVector<QPoint> verticalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool leftToRight) const;
|
||||
QVector<QPoint> verticalPoints(const QPoint& center,
|
||||
const int elements,
|
||||
const bool upToDown) const;
|
||||
const bool upToDown) const;
|
||||
|
||||
QRect intersectWithAreas(const QRect& rect);
|
||||
QRect intersectWithAreas(const QRect& rect);
|
||||
|
||||
QVector<CaptureToolButton*> m_vectorButtons;
|
||||
QVector<CaptureToolButton*> m_vectorButtons;
|
||||
|
||||
QRegion m_screenRegions;
|
||||
QRegion m_screenRegions;
|
||||
|
||||
QRect m_selection;
|
||||
QRect m_selection;
|
||||
|
||||
int m_separator;
|
||||
int m_buttonExtendedSize;
|
||||
int m_buttonBaseSize;
|
||||
int m_separator;
|
||||
int m_buttonExtendedSize;
|
||||
int m_buttonBaseSize;
|
||||
|
||||
bool m_buttonsAreInside;
|
||||
bool m_blockedRight;
|
||||
bool m_blockedLeft;
|
||||
bool m_blockedBotton;
|
||||
bool m_blockedTop;
|
||||
bool m_oneHorizontalBlocked;
|
||||
bool m_horizontalyBlocked;
|
||||
bool m_allSidesBlocked;
|
||||
bool m_buttonsAreInside;
|
||||
bool m_blockedRight;
|
||||
bool m_blockedLeft;
|
||||
bool m_blockedBotton;
|
||||
bool m_blockedTop;
|
||||
bool m_oneHorizontalBlocked;
|
||||
bool m_horizontalyBlocked;
|
||||
bool m_allSidesBlocked;
|
||||
|
||||
// aux methods
|
||||
void init();
|
||||
void resetRegionTrack();
|
||||
void updateBlockedSides();
|
||||
void expandSelection();
|
||||
void positionButtonsInside(int index);
|
||||
void ensureSelectionMinimunSize();
|
||||
void moveButtonsToPoints(const QVector<QPoint>& points, int& index);
|
||||
void adjustHorizontalCenter(QPoint& center);
|
||||
// aux methods
|
||||
void init();
|
||||
void resetRegionTrack();
|
||||
void updateBlockedSides();
|
||||
void expandSelection();
|
||||
void positionButtonsInside(int index);
|
||||
void ensureSelectionMinimunSize();
|
||||
void moveButtonsToPoints(const QVector<QPoint>& points, int& index);
|
||||
void adjustHorizontalCenter(QPoint& center);
|
||||
};
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
CaptureButton::CaptureButton(QWidget* parent)
|
||||
: QPushButton(parent)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
CaptureButton::CaptureButton(const QString& text, QWidget* parent)
|
||||
: QPushButton(text, parent)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
CaptureButton::CaptureButton(const QIcon& icon,
|
||||
@@ -38,56 +38,52 @@ CaptureButton::CaptureButton(const QIcon& icon,
|
||||
QWidget* parent)
|
||||
: QPushButton(icon, text, parent)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
void
|
||||
CaptureButton::init()
|
||||
void CaptureButton::init()
|
||||
{
|
||||
setCursor(Qt::ArrowCursor);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setCursor(Qt::ArrowCursor);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
auto dsEffect = new QGraphicsDropShadowEffect(this);
|
||||
dsEffect->setBlurRadius(5);
|
||||
dsEffect->setOffset(0);
|
||||
dsEffect->setColor(QColor(Qt::black));
|
||||
auto dsEffect = new QGraphicsDropShadowEffect(this);
|
||||
dsEffect->setBlurRadius(5);
|
||||
dsEffect->setOffset(0);
|
||||
dsEffect->setColor(QColor(Qt::black));
|
||||
|
||||
setGraphicsEffect(dsEffect);
|
||||
setGraphicsEffect(dsEffect);
|
||||
}
|
||||
|
||||
QString
|
||||
CaptureButton::globalStyleSheet()
|
||||
QString CaptureButton::globalStyleSheet()
|
||||
{
|
||||
return CaptureButton(nullptr).styleSheet();
|
||||
return CaptureButton(nullptr).styleSheet();
|
||||
}
|
||||
|
||||
QString
|
||||
CaptureButton::styleSheet() const
|
||||
QString CaptureButton::styleSheet() const
|
||||
{
|
||||
QString baseSheet = "CaptureButton { border: none;"
|
||||
"padding: 3px 8px;"
|
||||
"background-color: %1; color: %4 }"
|
||||
"CaptureToolButton { border-radius: %3;"
|
||||
"padding: 0; }"
|
||||
"CaptureButton:hover { background-color: %2; }"
|
||||
"CaptureButton:pressed:!hover { "
|
||||
"background-color: %1; }";
|
||||
// define color when mouse is hovering
|
||||
QColor contrast = ColorUtils::contrastColor(m_mainColor);
|
||||
// foreground color
|
||||
QColor color = ColorUtils::colorIsDark(m_mainColor) ? Qt::white : Qt::black;
|
||||
QString baseSheet = "CaptureButton { border: none;"
|
||||
"padding: 3px 8px;"
|
||||
"background-color: %1; color: %4 }"
|
||||
"CaptureToolButton { border-radius: %3;"
|
||||
"padding: 0; }"
|
||||
"CaptureButton:hover { background-color: %2; }"
|
||||
"CaptureButton:pressed:!hover { "
|
||||
"background-color: %1; }";
|
||||
// define color when mouse is hovering
|
||||
QColor contrast = ColorUtils::contrastColor(m_mainColor);
|
||||
// foreground color
|
||||
QColor color = ColorUtils::colorIsDark(m_mainColor) ? Qt::white : Qt::black;
|
||||
|
||||
return baseSheet.arg(m_mainColor.name())
|
||||
.arg(contrast.name())
|
||||
.arg(GlobalValues::buttonBaseSize() / 2)
|
||||
.arg(color.name());
|
||||
return baseSheet.arg(m_mainColor.name())
|
||||
.arg(contrast.name())
|
||||
.arg(GlobalValues::buttonBaseSize() / 2)
|
||||
.arg(color.name());
|
||||
}
|
||||
|
||||
void
|
||||
CaptureButton::setColor(const QColor& c)
|
||||
void CaptureButton::setColor(const QColor& c)
|
||||
{
|
||||
m_mainColor = c;
|
||||
setStyleSheet(styleSheet());
|
||||
m_mainColor = c;
|
||||
setStyleSheet(styleSheet());
|
||||
}
|
||||
|
||||
QColor CaptureButton::m_mainColor = ConfigHandler().uiMainColorValue();
|
||||
|
||||
@@ -21,24 +21,24 @@
|
||||
|
||||
class CaptureButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CaptureButton() = delete;
|
||||
CaptureButton(QWidget* parent = nullptr);
|
||||
CaptureButton(const QString& text, QWidget* parent = nullptr);
|
||||
CaptureButton(const QIcon& icon,
|
||||
const QString& text,
|
||||
QWidget* parent = nullptr);
|
||||
CaptureButton() = delete;
|
||||
CaptureButton(QWidget* parent = nullptr);
|
||||
CaptureButton(const QString& text, QWidget* parent = nullptr);
|
||||
CaptureButton(const QIcon& icon,
|
||||
const QString& text,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
static QString globalStyleSheet();
|
||||
static QString globalStyleSheet();
|
||||
|
||||
QString styleSheet() const;
|
||||
QString styleSheet() const;
|
||||
|
||||
void setColor(const QColor& c);
|
||||
void setColor(const QColor& c);
|
||||
|
||||
private:
|
||||
static QColor m_mainColor;
|
||||
static QColor m_mainColor;
|
||||
|
||||
void init();
|
||||
void init();
|
||||
};
|
||||
|
||||
@@ -35,142 +35,135 @@ CaptureToolButton::CaptureToolButton(const ButtonType t, QWidget* parent)
|
||||
: CaptureButton(parent)
|
||||
, m_buttonType(t)
|
||||
{
|
||||
initButton();
|
||||
if (t == TYPE_SELECTIONINDICATOR) {
|
||||
QFont f = this->font();
|
||||
setFont(QFont(f.family(), 7, QFont::Bold));
|
||||
} else {
|
||||
updateIcon();
|
||||
}
|
||||
initButton();
|
||||
if (t == TYPE_SELECTIONINDICATOR) {
|
||||
QFont f = this->font();
|
||||
setFont(QFont(f.family(), 7, QFont::Bold));
|
||||
} else {
|
||||
updateIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CaptureToolButton::initButton()
|
||||
void CaptureToolButton::initButton()
|
||||
{
|
||||
m_tool = ToolFactory().CreateTool(m_buttonType, this);
|
||||
m_tool = ToolFactory().CreateTool(m_buttonType, this);
|
||||
|
||||
resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
|
||||
setMask(QRegion(QRect(-1,
|
||||
-1,
|
||||
GlobalValues::buttonBaseSize() + 2,
|
||||
GlobalValues::buttonBaseSize() + 2),
|
||||
QRegion::Ellipse));
|
||||
resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
|
||||
setMask(QRegion(QRect(-1,
|
||||
-1,
|
||||
GlobalValues::buttonBaseSize() + 2,
|
||||
GlobalValues::buttonBaseSize() + 2),
|
||||
QRegion::Ellipse));
|
||||
|
||||
setToolTip(m_tool->description());
|
||||
setToolTip(m_tool->description());
|
||||
|
||||
m_emergeAnimation = new QPropertyAnimation(this, "size", this);
|
||||
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_emergeAnimation->setDuration(80);
|
||||
m_emergeAnimation->setStartValue(QSize(0, 0));
|
||||
m_emergeAnimation->setEndValue(
|
||||
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
|
||||
m_emergeAnimation = new QPropertyAnimation(this, "size", this);
|
||||
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_emergeAnimation->setDuration(80);
|
||||
m_emergeAnimation->setStartValue(QSize(0, 0));
|
||||
m_emergeAnimation->setEndValue(
|
||||
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
|
||||
}
|
||||
|
||||
void
|
||||
CaptureToolButton::updateIcon()
|
||||
void CaptureToolButton::updateIcon()
|
||||
{
|
||||
setIcon(icon());
|
||||
setIconSize(size() * 0.6);
|
||||
setIcon(icon());
|
||||
setIconSize(size() * 0.6);
|
||||
}
|
||||
|
||||
QVector<CaptureToolButton::ButtonType>
|
||||
CaptureToolButton::getIterableButtonTypes()
|
||||
{
|
||||
return iterableButtonTypes;
|
||||
return iterableButtonTypes;
|
||||
}
|
||||
|
||||
// get icon returns the icon for the type of button
|
||||
QIcon
|
||||
CaptureToolButton::icon() const
|
||||
QIcon CaptureToolButton::icon() const
|
||||
{
|
||||
return m_tool->icon(m_mainColor, true);
|
||||
return m_tool->icon(m_mainColor, true);
|
||||
}
|
||||
|
||||
void
|
||||
CaptureToolButton::mousePressEvent(QMouseEvent* e)
|
||||
void CaptureToolButton::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
emit pressedButton(this);
|
||||
emit pressed();
|
||||
}
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
emit pressedButton(this);
|
||||
emit pressed();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CaptureToolButton::animatedShow()
|
||||
void CaptureToolButton::animatedShow()
|
||||
{
|
||||
if (!isVisible()) {
|
||||
show();
|
||||
m_emergeAnimation->start();
|
||||
connect(m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
|
||||
}
|
||||
if (!isVisible()) {
|
||||
show();
|
||||
m_emergeAnimation->start();
|
||||
connect(
|
||||
m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
|
||||
}
|
||||
}
|
||||
|
||||
CaptureTool*
|
||||
CaptureToolButton::tool() const
|
||||
CaptureTool* CaptureToolButton::tool() const
|
||||
{
|
||||
return m_tool;
|
||||
return m_tool;
|
||||
}
|
||||
|
||||
void
|
||||
CaptureToolButton::setColor(const QColor& c)
|
||||
void CaptureToolButton::setColor(const QColor& c)
|
||||
{
|
||||
CaptureButton::setColor(c);
|
||||
updateIcon();
|
||||
CaptureButton::setColor(c);
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
QColor CaptureToolButton::m_mainColor = ConfigHandler().uiMainColorValue();
|
||||
|
||||
static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder{
|
||||
{ CaptureToolButton::TYPE_PENCIL, 0 },
|
||||
{ CaptureToolButton::TYPE_DRAWER, 1 },
|
||||
{ CaptureToolButton::TYPE_ARROW, 2 },
|
||||
{ CaptureToolButton::TYPE_SELECTION, 3 },
|
||||
{ CaptureToolButton::TYPE_RECTANGLE, 4 },
|
||||
{ CaptureToolButton::TYPE_CIRCLE, 5 },
|
||||
{ CaptureToolButton::TYPE_MARKER, 6 },
|
||||
{ CaptureToolButton::TYPE_TEXT, 7 },
|
||||
{ CaptureToolButton::TYPE_PIXELATE, 8 },
|
||||
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
|
||||
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
|
||||
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
|
||||
{ CaptureToolButton::TYPE_UNDO, 12 },
|
||||
{ CaptureToolButton::TYPE_REDO, 13 },
|
||||
{ CaptureToolButton::TYPE_COPY, 14 },
|
||||
{ CaptureToolButton::TYPE_SAVE, 15 },
|
||||
{ CaptureToolButton::TYPE_EXIT, 16 },
|
||||
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 17 },
|
||||
{ CaptureToolButton::TYPE_OPEN_APP, 18 },
|
||||
{ CaptureToolButton::TYPE_PIN, 19 },
|
||||
{ CaptureToolButton::TYPE_PENCIL, 0 },
|
||||
{ CaptureToolButton::TYPE_DRAWER, 1 },
|
||||
{ CaptureToolButton::TYPE_ARROW, 2 },
|
||||
{ CaptureToolButton::TYPE_SELECTION, 3 },
|
||||
{ CaptureToolButton::TYPE_RECTANGLE, 4 },
|
||||
{ CaptureToolButton::TYPE_CIRCLE, 5 },
|
||||
{ CaptureToolButton::TYPE_MARKER, 6 },
|
||||
{ CaptureToolButton::TYPE_TEXT, 7 },
|
||||
{ CaptureToolButton::TYPE_PIXELATE, 8 },
|
||||
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
|
||||
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
|
||||
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
|
||||
{ CaptureToolButton::TYPE_UNDO, 12 },
|
||||
{ CaptureToolButton::TYPE_REDO, 13 },
|
||||
{ CaptureToolButton::TYPE_COPY, 14 },
|
||||
{ CaptureToolButton::TYPE_SAVE, 15 },
|
||||
{ CaptureToolButton::TYPE_EXIT, 16 },
|
||||
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 17 },
|
||||
{ CaptureToolButton::TYPE_OPEN_APP, 18 },
|
||||
{ CaptureToolButton::TYPE_PIN, 19 },
|
||||
};
|
||||
|
||||
int
|
||||
CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
|
||||
int CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
|
||||
{
|
||||
auto it = buttonTypeOrder.find(b);
|
||||
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size()
|
||||
: it->second;
|
||||
auto it = buttonTypeOrder.find(b);
|
||||
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size()
|
||||
: it->second;
|
||||
}
|
||||
|
||||
QVector<CaptureToolButton::ButtonType>
|
||||
CaptureToolButton::iterableButtonTypes = {
|
||||
CaptureToolButton::TYPE_PENCIL,
|
||||
CaptureToolButton::TYPE_DRAWER,
|
||||
CaptureToolButton::TYPE_ARROW,
|
||||
CaptureToolButton::TYPE_SELECTION,
|
||||
CaptureToolButton::TYPE_RECTANGLE,
|
||||
CaptureToolButton::TYPE_CIRCLE,
|
||||
CaptureToolButton::TYPE_MARKER,
|
||||
CaptureToolButton::TYPE_TEXT,
|
||||
CaptureToolButton::TYPE_PIXELATE,
|
||||
CaptureToolButton::TYPE_SELECTIONINDICATOR,
|
||||
CaptureToolButton::TYPE_MOVESELECTION,
|
||||
CaptureToolButton::TYPE_UNDO,
|
||||
CaptureToolButton::TYPE_REDO,
|
||||
CaptureToolButton::TYPE_COPY,
|
||||
CaptureToolButton::TYPE_SAVE,
|
||||
CaptureToolButton::TYPE_EXIT,
|
||||
CaptureToolButton::TYPE_IMAGEUPLOADER,
|
||||
CaptureToolButton::TYPE_OPEN_APP,
|
||||
CaptureToolButton::TYPE_PIN,
|
||||
CaptureToolButton::TYPE_CIRCLECOUNT,
|
||||
CaptureToolButton::TYPE_PENCIL,
|
||||
CaptureToolButton::TYPE_DRAWER,
|
||||
CaptureToolButton::TYPE_ARROW,
|
||||
CaptureToolButton::TYPE_SELECTION,
|
||||
CaptureToolButton::TYPE_RECTANGLE,
|
||||
CaptureToolButton::TYPE_CIRCLE,
|
||||
CaptureToolButton::TYPE_MARKER,
|
||||
CaptureToolButton::TYPE_TEXT,
|
||||
CaptureToolButton::TYPE_PIXELATE,
|
||||
CaptureToolButton::TYPE_SELECTIONINDICATOR,
|
||||
CaptureToolButton::TYPE_MOVESELECTION,
|
||||
CaptureToolButton::TYPE_UNDO,
|
||||
CaptureToolButton::TYPE_REDO,
|
||||
CaptureToolButton::TYPE_COPY,
|
||||
CaptureToolButton::TYPE_SAVE,
|
||||
CaptureToolButton::TYPE_EXIT,
|
||||
CaptureToolButton::TYPE_IMAGEUPLOADER,
|
||||
CaptureToolButton::TYPE_OPEN_APP,
|
||||
CaptureToolButton::TYPE_PIN,
|
||||
CaptureToolButton::TYPE_CIRCLECOUNT,
|
||||
};
|
||||
|
||||
@@ -27,67 +27,67 @@ class CaptureTool;
|
||||
|
||||
class CaptureToolButton : public CaptureButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Don't forget to add the new types to CaptureButton::iterableButtonTypes
|
||||
// in the .cpp and the order value in the private array buttonTypeOrder
|
||||
enum ButtonType
|
||||
{
|
||||
TYPE_PENCIL = 0,
|
||||
TYPE_DRAWER = 1,
|
||||
TYPE_ARROW = 2,
|
||||
TYPE_SELECTION = 3,
|
||||
TYPE_RECTANGLE = 4,
|
||||
TYPE_CIRCLE = 5,
|
||||
TYPE_MARKER = 6,
|
||||
TYPE_SELECTIONINDICATOR = 7,
|
||||
TYPE_MOVESELECTION = 8,
|
||||
TYPE_UNDO = 9,
|
||||
TYPE_COPY = 10,
|
||||
TYPE_SAVE = 11,
|
||||
TYPE_EXIT = 12,
|
||||
TYPE_IMAGEUPLOADER = 13,
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_PIXELATE = 15,
|
||||
TYPE_REDO = 16,
|
||||
TYPE_PIN = 17,
|
||||
TYPE_TEXT = 18,
|
||||
TYPE_CIRCLECOUNT = 19,
|
||||
// Don't forget to add the new types to CaptureButton::iterableButtonTypes
|
||||
// in the .cpp and the order value in the private array buttonTypeOrder
|
||||
enum ButtonType
|
||||
{
|
||||
TYPE_PENCIL = 0,
|
||||
TYPE_DRAWER = 1,
|
||||
TYPE_ARROW = 2,
|
||||
TYPE_SELECTION = 3,
|
||||
TYPE_RECTANGLE = 4,
|
||||
TYPE_CIRCLE = 5,
|
||||
TYPE_MARKER = 6,
|
||||
TYPE_SELECTIONINDICATOR = 7,
|
||||
TYPE_MOVESELECTION = 8,
|
||||
TYPE_UNDO = 9,
|
||||
TYPE_COPY = 10,
|
||||
TYPE_SAVE = 11,
|
||||
TYPE_EXIT = 12,
|
||||
TYPE_IMAGEUPLOADER = 13,
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_PIXELATE = 15,
|
||||
TYPE_REDO = 16,
|
||||
TYPE_PIN = 17,
|
||||
TYPE_TEXT = 18,
|
||||
TYPE_CIRCLECOUNT = 19,
|
||||
|
||||
};
|
||||
Q_ENUM(ButtonType)
|
||||
};
|
||||
Q_ENUM(ButtonType)
|
||||
|
||||
explicit CaptureToolButton(const ButtonType, QWidget* parent = nullptr);
|
||||
explicit CaptureToolButton(const ButtonType, QWidget* parent = nullptr);
|
||||
|
||||
static QVector<CaptureToolButton::ButtonType> getIterableButtonTypes();
|
||||
static int getPriorityByButton(CaptureToolButton::ButtonType);
|
||||
static QVector<CaptureToolButton::ButtonType> getIterableButtonTypes();
|
||||
static int getPriorityByButton(CaptureToolButton::ButtonType);
|
||||
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
QIcon icon() const;
|
||||
CaptureTool* tool() const;
|
||||
QString name() const;
|
||||
QString description() const;
|
||||
QIcon icon() const;
|
||||
CaptureTool* tool() const;
|
||||
|
||||
void setColor(const QColor& c);
|
||||
void animatedShow();
|
||||
void setColor(const QColor& c);
|
||||
void animatedShow();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
static QVector<ButtonType> iterableButtonTypes;
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
static QVector<ButtonType> iterableButtonTypes;
|
||||
|
||||
CaptureTool* m_tool;
|
||||
CaptureTool* m_tool;
|
||||
|
||||
signals:
|
||||
void pressedButton(CaptureToolButton*);
|
||||
void pressedButton(CaptureToolButton*);
|
||||
|
||||
private:
|
||||
CaptureToolButton(QWidget* parent = nullptr);
|
||||
ButtonType m_buttonType;
|
||||
CaptureToolButton(QWidget* parent = nullptr);
|
||||
ButtonType m_buttonType;
|
||||
|
||||
QPropertyAnimation* m_emergeAnimation;
|
||||
QPropertyAnimation* m_emergeAnimation;
|
||||
|
||||
static QColor m_mainColor;
|
||||
static QColor m_mainColor;
|
||||
|
||||
void initButton();
|
||||
void updateIcon();
|
||||
void initButton();
|
||||
void updateIcon();
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -49,112 +49,112 @@ class HoverEventFilter;
|
||||
|
||||
class CaptureWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CaptureWidget(const uint id = 0,
|
||||
const QString& savePath = QString(),
|
||||
bool fullScreen = true,
|
||||
QWidget* parent = nullptr);
|
||||
~CaptureWidget();
|
||||
explicit CaptureWidget(const uint id = 0,
|
||||
const QString& savePath = QString(),
|
||||
bool fullScreen = true,
|
||||
QWidget* parent = nullptr);
|
||||
~CaptureWidget();
|
||||
|
||||
void updateButtons();
|
||||
QPixmap pixmap();
|
||||
void updateButtons();
|
||||
QPixmap pixmap();
|
||||
|
||||
public slots:
|
||||
void deleteToolwidgetOrClose();
|
||||
void deleteToolwidgetOrClose();
|
||||
|
||||
signals:
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureFailed(uint id);
|
||||
void colorChanged(const QColor& c);
|
||||
void thicknessChanged(const int thickness);
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureFailed(uint id);
|
||||
void colorChanged(const QColor& c);
|
||||
void thicknessChanged(const int thickness);
|
||||
|
||||
private slots:
|
||||
|
||||
// TODO replace with tools
|
||||
void copyScreenshot();
|
||||
void saveScreenshot();
|
||||
void undo();
|
||||
void redo();
|
||||
void togglePanel();
|
||||
void childEnter();
|
||||
void childLeave();
|
||||
// TODO replace with tools
|
||||
void copyScreenshot();
|
||||
void saveScreenshot();
|
||||
void undo();
|
||||
void redo();
|
||||
void togglePanel();
|
||||
void childEnter();
|
||||
void childLeave();
|
||||
|
||||
void leftResize();
|
||||
void rightResize();
|
||||
void upResize();
|
||||
void downResize();
|
||||
void leftResize();
|
||||
void rightResize();
|
||||
void upResize();
|
||||
void downResize();
|
||||
|
||||
void setState(CaptureToolButton* b);
|
||||
void processTool(CaptureTool* t);
|
||||
void handleButtonSignal(CaptureTool::Request r);
|
||||
void setDrawColor(const QColor& c);
|
||||
void setDrawThickness(const int& t);
|
||||
void incrementCircleCount();
|
||||
void decrementCircleCount();
|
||||
void setState(CaptureToolButton* b);
|
||||
void processTool(CaptureTool* t);
|
||||
void handleButtonSignal(CaptureTool::Request r);
|
||||
void setDrawColor(const QColor& c);
|
||||
void setDrawThickness(const int& t);
|
||||
void incrementCircleCount();
|
||||
void decrementCircleCount();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void mouseReleaseEvent(QMouseEvent*);
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
void keyReleaseEvent(QKeyEvent*);
|
||||
void wheelEvent(QWheelEvent*);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
void moveEvent(QMoveEvent*);
|
||||
void paintEvent(QPaintEvent*);
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void mouseReleaseEvent(QMouseEvent*);
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
void keyReleaseEvent(QKeyEvent*);
|
||||
void wheelEvent(QWheelEvent*);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
void moveEvent(QMoveEvent*);
|
||||
|
||||
// Context information
|
||||
CaptureContext m_context;
|
||||
// Context information
|
||||
CaptureContext m_context;
|
||||
|
||||
// Main ui color
|
||||
QColor m_uiColor;
|
||||
// Secondary ui color
|
||||
QColor m_contrastUiColor;
|
||||
// Main ui color
|
||||
QColor m_uiColor;
|
||||
// Secondary ui color
|
||||
QColor m_contrastUiColor;
|
||||
|
||||
// Outside selection opacity
|
||||
int m_opacity;
|
||||
// Outside selection opacity
|
||||
int m_opacity;
|
||||
|
||||
// utility flags
|
||||
bool m_mouseIsClicked;
|
||||
bool m_rightClick;
|
||||
bool m_newSelection;
|
||||
bool m_grabbing;
|
||||
bool m_showInitialMsg;
|
||||
bool m_captureDone;
|
||||
bool m_previewEnabled;
|
||||
bool m_adjustmentButtonPressed;
|
||||
// utility flags
|
||||
bool m_mouseIsClicked;
|
||||
bool m_rightClick;
|
||||
bool m_newSelection;
|
||||
bool m_grabbing;
|
||||
bool m_showInitialMsg;
|
||||
bool m_captureDone;
|
||||
bool m_previewEnabled;
|
||||
bool m_adjustmentButtonPressed;
|
||||
|
||||
private:
|
||||
void initContext(const QString& savePath, bool fullscreen);
|
||||
void initPanel();
|
||||
void initSelection();
|
||||
void initShortcuts();
|
||||
void updateSizeIndicator();
|
||||
void updateCursor();
|
||||
void pushToolToStack();
|
||||
void makeChild(QWidget* w);
|
||||
void initContext(const QString& savePath, bool fullscreen);
|
||||
void initPanel();
|
||||
void initSelection();
|
||||
void initShortcuts();
|
||||
void updateSizeIndicator();
|
||||
void updateCursor();
|
||||
void pushToolToStack();
|
||||
void makeChild(QWidget* w);
|
||||
|
||||
QRect extendedSelection() const;
|
||||
QRect extendedRect(QRect* r) const;
|
||||
QRect extendedSelection() const;
|
||||
QRect extendedRect(QRect* r) const;
|
||||
|
||||
QUndoStack m_undoStack;
|
||||
QPointer<CaptureToolButton> m_sizeIndButton;
|
||||
// Last pressed button
|
||||
QPointer<CaptureToolButton> m_activeButton;
|
||||
QPointer<CaptureTool> m_activeTool;
|
||||
QPointer<QWidget> m_toolWidget;
|
||||
QUndoStack m_undoStack;
|
||||
QPointer<CaptureToolButton> m_sizeIndButton;
|
||||
// Last pressed button
|
||||
QPointer<CaptureToolButton> m_activeButton;
|
||||
QPointer<CaptureTool> m_activeTool;
|
||||
QPointer<QWidget> m_toolWidget;
|
||||
|
||||
ButtonHandler* m_buttonHandler;
|
||||
UtilityPanel* m_panel;
|
||||
ColorPicker* m_colorPicker;
|
||||
ConfigHandler m_config;
|
||||
NotifierBox* m_notifierBox;
|
||||
HoverEventFilter* m_eventFilter;
|
||||
SelectionWidget* m_selection;
|
||||
ButtonHandler* m_buttonHandler;
|
||||
UtilityPanel* m_panel;
|
||||
ColorPicker* m_colorPicker;
|
||||
ConfigHandler m_config;
|
||||
NotifierBox* m_notifierBox;
|
||||
HoverEventFilter* m_eventFilter;
|
||||
SelectionWidget* m_selection;
|
||||
|
||||
QPoint m_dragStartPoint;
|
||||
SelectionWidget::SideType m_mouseOverHandle;
|
||||
uint m_id;
|
||||
QPoint m_dragStartPoint;
|
||||
SelectionWidget::SideType m_mouseOverHandle;
|
||||
uint m_id;
|
||||
};
|
||||
|
||||
@@ -24,102 +24,96 @@
|
||||
ColorPicker::ColorPicker(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_colorList = config.getUserColors();
|
||||
m_colorAreaSize = GlobalValues::buttonBaseSize() * 0.6;
|
||||
setMouseTracking(true);
|
||||
// save the color values in member variables for faster access
|
||||
m_uiColor = config.uiMainColorValue();
|
||||
m_drawColor = config.drawColorValue();
|
||||
// extraSize represents the extra space needed for the highlight of the
|
||||
// selected color.
|
||||
const int extraSize = 6;
|
||||
double radius = (m_colorList.size() * m_colorAreaSize / 1.3) / (3.141592);
|
||||
resize(radius * 2 + m_colorAreaSize + extraSize,
|
||||
radius * 2 + m_colorAreaSize + extraSize);
|
||||
double degree = 360 / (m_colorList.size());
|
||||
double degreeAcum = degree;
|
||||
// this line is the radius of the circle which will be rotated to add
|
||||
// the color components.
|
||||
QLineF baseLine =
|
||||
QLineF(QPoint(radius + extraSize / 2, radius + extraSize / 2),
|
||||
QPoint(radius * 2, radius));
|
||||
ConfigHandler config;
|
||||
m_colorList = config.getUserColors();
|
||||
m_colorAreaSize = GlobalValues::buttonBaseSize() * 0.6;
|
||||
setMouseTracking(true);
|
||||
// save the color values in member variables for faster access
|
||||
m_uiColor = config.uiMainColorValue();
|
||||
m_drawColor = config.drawColorValue();
|
||||
// extraSize represents the extra space needed for the highlight of the
|
||||
// selected color.
|
||||
const int extraSize = 6;
|
||||
double radius = (m_colorList.size() * m_colorAreaSize / 1.3) / (3.141592);
|
||||
resize(radius * 2 + m_colorAreaSize + extraSize,
|
||||
radius * 2 + m_colorAreaSize + extraSize);
|
||||
double degree = 360 / (m_colorList.size());
|
||||
double degreeAcum = degree;
|
||||
// this line is the radius of the circle which will be rotated to add
|
||||
// the color components.
|
||||
QLineF baseLine =
|
||||
QLineF(QPoint(radius + extraSize / 2, radius + extraSize / 2),
|
||||
QPoint(radius * 2, radius));
|
||||
|
||||
for (int i = 0; i < m_colorList.size(); ++i) {
|
||||
m_colorAreaList.append(
|
||||
QRect(baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize));
|
||||
baseLine.setAngle(degreeAcum);
|
||||
degreeAcum += degree;
|
||||
}
|
||||
}
|
||||
|
||||
QColor
|
||||
ColorPicker::drawColor()
|
||||
{
|
||||
return m_drawColor;
|
||||
}
|
||||
|
||||
void
|
||||
ColorPicker::show()
|
||||
{
|
||||
grabMouse();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void
|
||||
ColorPicker::hide()
|
||||
{
|
||||
releaseMouse();
|
||||
QWidget::hide();
|
||||
}
|
||||
|
||||
void
|
||||
ColorPicker::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QVector<QRect> rects = handleMask();
|
||||
painter.setPen(QColor(Qt::black));
|
||||
for (int i = 0; i < rects.size(); ++i) {
|
||||
// draw the highlight when we have to draw the selected color
|
||||
if (m_drawColor == QColor(m_colorList.at(i))) {
|
||||
QColor c = QColor(m_uiColor);
|
||||
c.setAlpha(155);
|
||||
painter.setBrush(c);
|
||||
c.setAlpha(100);
|
||||
painter.setPen(c);
|
||||
QRect highlight = rects.at(i);
|
||||
highlight.moveTo(highlight.x() - 3, highlight.y() - 3);
|
||||
highlight.setHeight(highlight.height() + 6);
|
||||
highlight.setWidth(highlight.width() + 6);
|
||||
painter.drawRoundedRect(highlight, 100, 100);
|
||||
painter.setPen(QColor(Qt::black));
|
||||
for (int i = 0; i < m_colorList.size(); ++i) {
|
||||
m_colorAreaList.append(QRect(
|
||||
baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize));
|
||||
baseLine.setAngle(degreeAcum);
|
||||
degreeAcum += degree;
|
||||
}
|
||||
painter.setBrush(QColor(m_colorList.at(i)));
|
||||
painter.drawRoundedRect(rects.at(i), 100, 100);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ColorPicker::mouseMoveEvent(QMouseEvent* e)
|
||||
QColor ColorPicker::drawColor()
|
||||
{
|
||||
for (int i = 0; i < m_colorList.size(); ++i) {
|
||||
if (m_colorAreaList.at(i).contains(e->pos())) {
|
||||
m_drawColor = m_colorList.at(i);
|
||||
emit colorSelected(m_drawColor);
|
||||
update();
|
||||
break;
|
||||
return m_drawColor;
|
||||
}
|
||||
|
||||
void ColorPicker::show()
|
||||
{
|
||||
grabMouse();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void ColorPicker::hide()
|
||||
{
|
||||
releaseMouse();
|
||||
QWidget::hide();
|
||||
}
|
||||
|
||||
void ColorPicker::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QVector<QRect> rects = handleMask();
|
||||
painter.setPen(QColor(Qt::black));
|
||||
for (int i = 0; i < rects.size(); ++i) {
|
||||
// draw the highlight when we have to draw the selected color
|
||||
if (m_drawColor == QColor(m_colorList.at(i))) {
|
||||
QColor c = QColor(m_uiColor);
|
||||
c.setAlpha(155);
|
||||
painter.setBrush(c);
|
||||
c.setAlpha(100);
|
||||
painter.setPen(c);
|
||||
QRect highlight = rects.at(i);
|
||||
highlight.moveTo(highlight.x() - 3, highlight.y() - 3);
|
||||
highlight.setHeight(highlight.height() + 6);
|
||||
highlight.setWidth(highlight.width() + 6);
|
||||
painter.drawRoundedRect(highlight, 100, 100);
|
||||
painter.setPen(QColor(Qt::black));
|
||||
}
|
||||
painter.setBrush(QColor(m_colorList.at(i)));
|
||||
painter.drawRoundedRect(rects.at(i), 100, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRect>
|
||||
ColorPicker::handleMask() const
|
||||
void ColorPicker::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
QVector<QRect> areas;
|
||||
for (const QRect& rect : m_colorAreaList) {
|
||||
areas.append(rect);
|
||||
}
|
||||
return areas;
|
||||
for (int i = 0; i < m_colorList.size(); ++i) {
|
||||
if (m_colorAreaList.at(i).contains(e->pos())) {
|
||||
m_drawColor = m_colorList.at(i);
|
||||
emit colorSelected(m_drawColor);
|
||||
update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRect> ColorPicker::handleMask() const
|
||||
{
|
||||
QVector<QRect> areas;
|
||||
for (const QRect& rect : m_colorAreaList) {
|
||||
areas.append(rect);
|
||||
}
|
||||
return areas;
|
||||
}
|
||||
|
||||
@@ -21,28 +21,28 @@
|
||||
|
||||
class ColorPicker : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ColorPicker(QWidget* parent = nullptr);
|
||||
explicit ColorPicker(QWidget* parent = nullptr);
|
||||
|
||||
QColor drawColor();
|
||||
QColor drawColor();
|
||||
|
||||
void show();
|
||||
void hide();
|
||||
void show();
|
||||
void hide();
|
||||
|
||||
signals:
|
||||
void colorSelected(QColor c);
|
||||
void colorSelected(QColor c);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
void paintEvent(QPaintEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*);
|
||||
|
||||
QVector<QRect> handleMask() const;
|
||||
QVector<QRect> handleMask() const;
|
||||
|
||||
private:
|
||||
int m_colorAreaSize;
|
||||
QVector<QRect> m_colorAreaList;
|
||||
QVector<QColor> m_colorList;
|
||||
int m_colorAreaSize;
|
||||
QVector<QRect> m_colorAreaList;
|
||||
QVector<QColor> m_colorList;
|
||||
|
||||
QColor m_uiColor, m_drawColor;
|
||||
QColor m_uiColor, m_drawColor;
|
||||
};
|
||||
|
||||
@@ -30,19 +30,18 @@ HoverEventFilter::HoverEventFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
bool
|
||||
HoverEventFilter::eventFilter(QObject* watched, QEvent* event)
|
||||
bool HoverEventFilter::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
QEvent::Type t = event->type();
|
||||
switch (t) {
|
||||
case QEvent::Enter:
|
||||
emit hoverIn(watched);
|
||||
break;
|
||||
case QEvent::Leave:
|
||||
emit hoverOut(watched);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
QEvent::Type t = event->type();
|
||||
switch (t) {
|
||||
case QEvent::Enter:
|
||||
emit hoverIn(watched);
|
||||
break;
|
||||
case QEvent::Leave:
|
||||
emit hoverOut(watched);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
|
||||
class HoverEventFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HoverEventFilter(QObject* parent = nullptr);
|
||||
explicit HoverEventFilter(QObject* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void hoverIn(QObject*);
|
||||
void hoverOut(QObject*);
|
||||
void hoverIn(QObject*);
|
||||
void hoverOut(QObject*);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* watched, QEvent* event);
|
||||
bool eventFilter(QObject* watched, QEvent* event);
|
||||
};
|
||||
|
||||
@@ -22,19 +22,17 @@ ModificationCommand::ModificationCommand(QPixmap* p, CaptureTool* t)
|
||||
: m_pixmap(p)
|
||||
, m_tool(t)
|
||||
{
|
||||
setText(t->name());
|
||||
setText(t->name());
|
||||
}
|
||||
|
||||
void
|
||||
ModificationCommand::undo()
|
||||
void ModificationCommand::undo()
|
||||
{
|
||||
m_tool->undo(*m_pixmap);
|
||||
m_tool->undo(*m_pixmap);
|
||||
}
|
||||
|
||||
void
|
||||
ModificationCommand::redo()
|
||||
void ModificationCommand::redo()
|
||||
{
|
||||
QPainter p(m_pixmap);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
m_tool->process(p, *m_pixmap, true);
|
||||
QPainter p(m_pixmap);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
m_tool->process(p, *m_pixmap, true);
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
class ModificationCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ModificationCommand(QPixmap*, CaptureTool*);
|
||||
ModificationCommand(QPixmap*, CaptureTool*);
|
||||
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
QPixmap* m_pixmap;
|
||||
QScopedPointer<CaptureTool> m_tool;
|
||||
QPixmap* m_pixmap;
|
||||
QScopedPointer<CaptureTool> m_tool;
|
||||
};
|
||||
|
||||
@@ -26,52 +26,48 @@
|
||||
NotifierBox::NotifierBox(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(1200);
|
||||
connect(m_timer, &QTimer::timeout, this, &NotifierBox::hide);
|
||||
m_bgColor = ConfigHandler().uiMainColorValue();
|
||||
m_foregroundColor =
|
||||
(ColorUtils::colorIsDark(m_bgColor) ? Qt::white : Qt::black);
|
||||
m_bgColor.setAlpha(180);
|
||||
const int size =
|
||||
(GlobalValues::buttonBaseSize() + GlobalValues::buttonBaseSize() / 2) *
|
||||
qApp->devicePixelRatio();
|
||||
setFixedSize(QSize(size, size));
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(1200);
|
||||
connect(m_timer, &QTimer::timeout, this, &NotifierBox::hide);
|
||||
m_bgColor = ConfigHandler().uiMainColorValue();
|
||||
m_foregroundColor =
|
||||
(ColorUtils::colorIsDark(m_bgColor) ? Qt::white : Qt::black);
|
||||
m_bgColor.setAlpha(180);
|
||||
const int size =
|
||||
(GlobalValues::buttonBaseSize() + GlobalValues::buttonBaseSize() / 2) *
|
||||
qApp->devicePixelRatio();
|
||||
setFixedSize(QSize(size, size));
|
||||
}
|
||||
|
||||
void
|
||||
NotifierBox::enterEvent(QEvent*)
|
||||
void NotifierBox::enterEvent(QEvent*)
|
||||
{
|
||||
hide();
|
||||
hide();
|
||||
}
|
||||
|
||||
void
|
||||
NotifierBox::paintEvent(QPaintEvent*)
|
||||
void NotifierBox::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
// draw Elipse
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBrush(QBrush(m_bgColor, Qt::SolidPattern));
|
||||
painter.setPen(QPen(Qt::transparent));
|
||||
painter.drawEllipse(rect());
|
||||
// Draw the text:
|
||||
painter.setPen(QPen(m_foregroundColor));
|
||||
painter.drawText(rect(), Qt::AlignCenter, m_message);
|
||||
QPainter painter(this);
|
||||
// draw Elipse
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBrush(QBrush(m_bgColor, Qt::SolidPattern));
|
||||
painter.setPen(QPen(Qt::transparent));
|
||||
painter.drawEllipse(rect());
|
||||
// Draw the text:
|
||||
painter.setPen(QPen(m_foregroundColor));
|
||||
painter.drawText(rect(), Qt::AlignCenter, m_message);
|
||||
}
|
||||
|
||||
void
|
||||
NotifierBox::showMessage(const QString& msg)
|
||||
void NotifierBox::showMessage(const QString& msg)
|
||||
{
|
||||
m_message = msg;
|
||||
update();
|
||||
show();
|
||||
m_timer->start();
|
||||
m_message = msg;
|
||||
update();
|
||||
show();
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
void
|
||||
NotifierBox::showColor(const QColor& color)
|
||||
void NotifierBox::showColor(const QColor& color)
|
||||
{
|
||||
Q_UNUSED(color);
|
||||
m_message = QLatin1String("");
|
||||
Q_UNUSED(color);
|
||||
m_message = QLatin1String("");
|
||||
}
|
||||
|
||||
@@ -23,21 +23,21 @@ class QTimer;
|
||||
|
||||
class NotifierBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NotifierBox(QWidget* parent = nullptr);
|
||||
explicit NotifierBox(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual void enterEvent(QEvent*);
|
||||
virtual void paintEvent(QPaintEvent*);
|
||||
virtual void enterEvent(QEvent*);
|
||||
virtual void paintEvent(QPaintEvent*);
|
||||
|
||||
public slots:
|
||||
void showMessage(const QString& msg);
|
||||
void showColor(const QColor& color);
|
||||
void showMessage(const QString& msg);
|
||||
void showColor(const QColor& color);
|
||||
|
||||
private:
|
||||
QTimer* m_timer;
|
||||
QString m_message;
|
||||
QColor m_bgColor;
|
||||
QColor m_foregroundColor;
|
||||
QTimer* m_timer;
|
||||
QString m_message;
|
||||
QColor m_bgColor;
|
||||
QColor m_foregroundColor;
|
||||
};
|
||||
|
||||
@@ -24,128 +24,119 @@ SelectionWidget::SelectionWidget(const QColor& c, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_color(c)
|
||||
{
|
||||
m_animation = new QPropertyAnimation(this, "geometry", this);
|
||||
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_animation->setDuration(200);
|
||||
connect(m_animation,
|
||||
&QPropertyAnimation::finished,
|
||||
this,
|
||||
&SelectionWidget::animationEnded);
|
||||
m_animation = new QPropertyAnimation(this, "geometry", this);
|
||||
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_animation->setDuration(200);
|
||||
connect(m_animation,
|
||||
&QPropertyAnimation::finished,
|
||||
this,
|
||||
&SelectionWidget::animationEnded);
|
||||
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
int sideVal = GlobalValues::buttonBaseSize() * 0.6;
|
||||
int handleSide = sideVal / 2;
|
||||
const QRect areaRect(0, 0, sideVal, sideVal);
|
||||
const QRect handleRect(0, 0, handleSide, handleSide);
|
||||
m_TLHandle = m_TRHandle = m_BLHandle = m_BRHandle = m_LHandle = m_THandle =
|
||||
m_RHandle = m_BHandle = handleRect;
|
||||
m_TLArea = m_TRArea = m_BLArea = m_BRArea = areaRect;
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
int sideVal = GlobalValues::buttonBaseSize() * 0.6;
|
||||
int handleSide = sideVal / 2;
|
||||
const QRect areaRect(0, 0, sideVal, sideVal);
|
||||
const QRect handleRect(0, 0, handleSide, handleSide);
|
||||
m_TLHandle = m_TRHandle = m_BLHandle = m_BRHandle = m_LHandle = m_THandle =
|
||||
m_RHandle = m_BHandle = handleRect;
|
||||
m_TLArea = m_TRArea = m_BLArea = m_BRArea = areaRect;
|
||||
|
||||
m_areaOffset = QPoint(-sideVal / 2, -sideVal / 2);
|
||||
m_handleOffset = QPoint(-handleSide / 2, -handleSide / 2);
|
||||
m_areaOffset = QPoint(-sideVal / 2, -sideVal / 2);
|
||||
m_handleOffset = QPoint(-handleSide / 2, -handleSide / 2);
|
||||
}
|
||||
|
||||
SelectionWidget::SideType
|
||||
SelectionWidget::getMouseSide(const QPoint& point) const
|
||||
SelectionWidget::SideType SelectionWidget::getMouseSide(
|
||||
const QPoint& point) const
|
||||
{
|
||||
if (m_TLArea.contains(point)) {
|
||||
return TOPLEFT_SIDE;
|
||||
} else if (m_TRArea.contains(point)) {
|
||||
return TOPRIGHT_SIDE;
|
||||
} else if (m_BLArea.contains(point)) {
|
||||
return BOTTONLEFT_SIDE;
|
||||
} else if (m_BRArea.contains(point)) {
|
||||
return BOTTONRIGHT_SIDE;
|
||||
} else if (m_LArea.contains(point)) {
|
||||
return LEFT_SIDE;
|
||||
} else if (m_TArea.contains(point)) {
|
||||
return TOP_SIDE;
|
||||
} else if (m_RArea.contains(point)) {
|
||||
return RIGHT_SIDE;
|
||||
} else if (m_BArea.contains(point)) {
|
||||
return BOTTON_SIDE;
|
||||
} else {
|
||||
return NO_SIDE;
|
||||
}
|
||||
if (m_TLArea.contains(point)) {
|
||||
return TOPLEFT_SIDE;
|
||||
} else if (m_TRArea.contains(point)) {
|
||||
return TOPRIGHT_SIDE;
|
||||
} else if (m_BLArea.contains(point)) {
|
||||
return BOTTONLEFT_SIDE;
|
||||
} else if (m_BRArea.contains(point)) {
|
||||
return BOTTONRIGHT_SIDE;
|
||||
} else if (m_LArea.contains(point)) {
|
||||
return LEFT_SIDE;
|
||||
} else if (m_TArea.contains(point)) {
|
||||
return TOP_SIDE;
|
||||
} else if (m_RArea.contains(point)) {
|
||||
return RIGHT_SIDE;
|
||||
} else if (m_BArea.contains(point)) {
|
||||
return BOTTON_SIDE;
|
||||
} else {
|
||||
return NO_SIDE;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRect>
|
||||
SelectionWidget::handlerAreas()
|
||||
QVector<QRect> SelectionWidget::handlerAreas()
|
||||
{
|
||||
QVector<QRect> areas;
|
||||
areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle << m_LHandle
|
||||
<< m_THandle << m_RHandle << m_BHandle;
|
||||
return areas;
|
||||
QVector<QRect> areas;
|
||||
areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle << m_LHandle
|
||||
<< m_THandle << m_RHandle << m_BHandle;
|
||||
return areas;
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::setGeometryAnimated(const QRect& r)
|
||||
void SelectionWidget::setGeometryAnimated(const QRect& r)
|
||||
{
|
||||
if (isVisible()) {
|
||||
m_animation->setStartValue(geometry());
|
||||
m_animation->setEndValue(r);
|
||||
m_animation->start();
|
||||
}
|
||||
if (isVisible()) {
|
||||
m_animation->setStartValue(geometry());
|
||||
m_animation->setEndValue(r);
|
||||
m_animation->start();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::saveGeometry()
|
||||
void SelectionWidget::saveGeometry()
|
||||
{
|
||||
m_geometryBackup = geometry();
|
||||
m_geometryBackup = geometry();
|
||||
}
|
||||
|
||||
QRect
|
||||
SelectionWidget::savedGeometry()
|
||||
QRect SelectionWidget::savedGeometry()
|
||||
{
|
||||
return m_geometryBackup;
|
||||
return m_geometryBackup;
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::paintEvent(QPaintEvent*)
|
||||
void SelectionWidget::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.setPen(m_color);
|
||||
p.drawRect(rect() + QMargins(0, 0, -1, -1));
|
||||
QPainter p(this);
|
||||
p.setPen(m_color);
|
||||
p.drawRect(rect() + QMargins(0, 0, -1, -1));
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::resizeEvent(QResizeEvent*)
|
||||
void SelectionWidget::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
updateAreas();
|
||||
updateAreas();
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::moveEvent(QMoveEvent*)
|
||||
void SelectionWidget::moveEvent(QMoveEvent*)
|
||||
{
|
||||
updateAreas();
|
||||
updateAreas();
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::updateColor(const QColor& c)
|
||||
void SelectionWidget::updateColor(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void
|
||||
SelectionWidget::updateAreas()
|
||||
void SelectionWidget::updateAreas()
|
||||
{
|
||||
QRect r = rect();
|
||||
m_TLArea.moveTo(m_areaOffset + pos());
|
||||
m_TRArea.moveTo(r.topRight() + m_areaOffset + pos());
|
||||
m_BLArea.moveTo(r.bottomLeft() + m_areaOffset + pos());
|
||||
m_BRArea.moveTo(r.bottomRight() + m_areaOffset + pos());
|
||||
QRect r = rect();
|
||||
m_TLArea.moveTo(m_areaOffset + pos());
|
||||
m_TRArea.moveTo(r.topRight() + m_areaOffset + pos());
|
||||
m_BLArea.moveTo(r.bottomLeft() + m_areaOffset + pos());
|
||||
m_BRArea.moveTo(r.bottomRight() + m_areaOffset + pos());
|
||||
|
||||
m_LArea = QRect(m_TLArea.bottomLeft(), m_BLArea.topRight());
|
||||
m_TArea = QRect(m_TLArea.topRight(), m_TRArea.bottomLeft());
|
||||
m_RArea = QRect(m_TRArea.bottomLeft(), m_BRArea.topRight());
|
||||
m_BArea = QRect(m_BLArea.topRight(), m_BRArea.bottomLeft());
|
||||
m_LArea = QRect(m_TLArea.bottomLeft(), m_BLArea.topRight());
|
||||
m_TArea = QRect(m_TLArea.topRight(), m_TRArea.bottomLeft());
|
||||
m_RArea = QRect(m_TRArea.bottomLeft(), m_BRArea.topRight());
|
||||
m_BArea = QRect(m_BLArea.topRight(), m_BRArea.bottomLeft());
|
||||
|
||||
m_TLHandle.moveTo(m_TLArea.center() + m_handleOffset);
|
||||
m_BLHandle.moveTo(m_BLArea.center() + m_handleOffset);
|
||||
m_TRHandle.moveTo(m_TRArea.center() + m_handleOffset);
|
||||
m_BRHandle.moveTo(m_BRArea.center() + m_handleOffset);
|
||||
m_LHandle.moveTo(m_LArea.center() + m_handleOffset);
|
||||
m_THandle.moveTo(m_TArea.center() + m_handleOffset);
|
||||
m_RHandle.moveTo(m_RArea.center() + m_handleOffset);
|
||||
m_BHandle.moveTo(m_BArea.center() + m_handleOffset);
|
||||
m_TLHandle.moveTo(m_TLArea.center() + m_handleOffset);
|
||||
m_BLHandle.moveTo(m_BLArea.center() + m_handleOffset);
|
||||
m_TRHandle.moveTo(m_TRArea.center() + m_handleOffset);
|
||||
m_BRHandle.moveTo(m_BRArea.center() + m_handleOffset);
|
||||
m_LHandle.moveTo(m_LArea.center() + m_handleOffset);
|
||||
m_THandle.moveTo(m_TArea.center() + m_handleOffset);
|
||||
m_RHandle.moveTo(m_RArea.center() + m_handleOffset);
|
||||
m_BHandle.moveTo(m_BArea.center() + m_handleOffset);
|
||||
}
|
||||
|
||||
@@ -23,58 +23,58 @@ class QPropertyAnimation;
|
||||
|
||||
class SelectionWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum SideType
|
||||
{
|
||||
TOPLEFT_SIDE,
|
||||
BOTTONLEFT_SIDE,
|
||||
TOPRIGHT_SIDE,
|
||||
BOTTONRIGHT_SIDE,
|
||||
TOP_SIDE,
|
||||
BOTTON_SIDE,
|
||||
RIGHT_SIDE,
|
||||
LEFT_SIDE,
|
||||
NO_SIDE,
|
||||
};
|
||||
enum SideType
|
||||
{
|
||||
TOPLEFT_SIDE,
|
||||
BOTTONLEFT_SIDE,
|
||||
TOPRIGHT_SIDE,
|
||||
BOTTONRIGHT_SIDE,
|
||||
TOP_SIDE,
|
||||
BOTTON_SIDE,
|
||||
RIGHT_SIDE,
|
||||
LEFT_SIDE,
|
||||
NO_SIDE,
|
||||
};
|
||||
|
||||
explicit SelectionWidget(const QColor& c, QWidget* parent = nullptr);
|
||||
explicit SelectionWidget(const QColor& c, QWidget* parent = nullptr);
|
||||
|
||||
SideType getMouseSide(const QPoint& point) const;
|
||||
QVector<QRect> handlerAreas();
|
||||
SideType getMouseSide(const QPoint& point) const;
|
||||
QVector<QRect> handlerAreas();
|
||||
|
||||
void setGeometryAnimated(const QRect& r);
|
||||
void saveGeometry();
|
||||
QRect savedGeometry();
|
||||
void setGeometryAnimated(const QRect& r);
|
||||
void saveGeometry();
|
||||
QRect savedGeometry();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
void moveEvent(QMoveEvent*);
|
||||
void paintEvent(QPaintEvent*);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
void moveEvent(QMoveEvent*);
|
||||
|
||||
signals:
|
||||
void animationEnded();
|
||||
void animationEnded();
|
||||
|
||||
public slots:
|
||||
void updateColor(const QColor& c);
|
||||
void updateColor(const QColor& c);
|
||||
|
||||
private:
|
||||
void updateAreas();
|
||||
void updateAreas();
|
||||
|
||||
QPropertyAnimation* m_animation;
|
||||
QPropertyAnimation* m_animation;
|
||||
|
||||
QColor m_color;
|
||||
QPoint m_areaOffset;
|
||||
QPoint m_handleOffset;
|
||||
QRect m_geometryBackup;
|
||||
QColor m_color;
|
||||
QPoint m_areaOffset;
|
||||
QPoint m_handleOffset;
|
||||
QRect m_geometryBackup;
|
||||
|
||||
// naming convention for handles
|
||||
// T top, B bottom, R Right, L left
|
||||
// 2 letters: a corner
|
||||
// 1 letter: the handle on the middle of the corresponding side
|
||||
QRect m_TLHandle, m_TRHandle, m_BLHandle, m_BRHandle;
|
||||
QRect m_LHandle, m_THandle, m_RHandle, m_BHandle;
|
||||
// naming convention for handles
|
||||
// T top, B bottom, R Right, L left
|
||||
// 2 letters: a corner
|
||||
// 1 letter: the handle on the middle of the corresponding side
|
||||
QRect m_TLHandle, m_TRHandle, m_BLHandle, m_BRHandle;
|
||||
QRect m_LHandle, m_THandle, m_RHandle, m_BHandle;
|
||||
|
||||
QRect m_TLArea, m_TRArea, m_BLArea, m_BRArea;
|
||||
QRect m_LArea, m_TArea, m_RArea, m_BArea;
|
||||
QRect m_TLArea, m_TRArea, m_BLArea, m_BRArea;
|
||||
QRect m_LArea, m_TArea, m_RArea, m_BArea;
|
||||
};
|
||||
|
||||
@@ -40,130 +40,126 @@ CaptureLauncher::CaptureLauncher(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_id(0)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(Controller::getInstance(),
|
||||
&Controller::captureTaken,
|
||||
this,
|
||||
&CaptureLauncher::captureTaken);
|
||||
connect(Controller::getInstance(),
|
||||
&Controller::captureFailed,
|
||||
this,
|
||||
&CaptureLauncher::captureFailed);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(Controller::getInstance(),
|
||||
&Controller::captureTaken,
|
||||
this,
|
||||
&CaptureLauncher::captureTaken);
|
||||
connect(Controller::getInstance(),
|
||||
&Controller::captureFailed,
|
||||
this,
|
||||
&CaptureLauncher::captureFailed);
|
||||
|
||||
m_imageLabel = new ImageLabel(this);
|
||||
bool ok;
|
||||
m_imageLabel->setScreenshot(ScreenGrabber().grabEntireDesktop(ok));
|
||||
if (!ok) {
|
||||
}
|
||||
m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
connect(m_imageLabel,
|
||||
&ImageLabel::dragInitiated,
|
||||
this,
|
||||
&CaptureLauncher::startDrag);
|
||||
m_imageLabel = new ImageLabel(this);
|
||||
bool ok;
|
||||
m_imageLabel->setScreenshot(ScreenGrabber().grabEntireDesktop(ok));
|
||||
if (!ok) {
|
||||
}
|
||||
m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
connect(m_imageLabel,
|
||||
&ImageLabel::dragInitiated,
|
||||
this,
|
||||
&CaptureLauncher::startDrag);
|
||||
|
||||
QGridLayout* layout = new QGridLayout(this);
|
||||
layout->addWidget(m_imageLabel, 0, 0);
|
||||
QGridLayout* layout = new QGridLayout(this);
|
||||
layout->addWidget(m_imageLabel, 0, 0);
|
||||
|
||||
m_CaptureModeLabel = new QLabel(tr("<b>Capture Mode</b>"));
|
||||
m_CaptureModeLabel = new QLabel(tr("<b>Capture Mode</b>"));
|
||||
|
||||
m_captureType = new QComboBox();
|
||||
m_captureType->setMinimumWidth(240);
|
||||
// TODO remember number
|
||||
m_captureType->insertItem(
|
||||
1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
|
||||
m_captureType->insertItem(
|
||||
2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
|
||||
// m_captureType->insertItem(3, tr("Single Screen"),
|
||||
// CaptureRequest::SCREEN_MODE);
|
||||
m_captureType = new QComboBox();
|
||||
m_captureType->setMinimumWidth(240);
|
||||
// TODO remember number
|
||||
m_captureType->insertItem(
|
||||
1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
|
||||
m_captureType->insertItem(
|
||||
2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
|
||||
// m_captureType->insertItem(3, tr("Single Screen"),
|
||||
// CaptureRequest::SCREEN_MODE);
|
||||
|
||||
m_delaySpinBox = new QSpinBox();
|
||||
m_delaySpinBox->setSingleStep(1.0);
|
||||
m_delaySpinBox->setMinimum(0.0);
|
||||
m_delaySpinBox->setMaximum(999.0);
|
||||
m_delaySpinBox->setSpecialValueText(tr("No Delay"));
|
||||
m_delaySpinBox->setMinimumWidth(160);
|
||||
// with QT 5.7 qOverload<int>(&QSpinBox::valueChanged),
|
||||
connect(m_delaySpinBox,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
||||
this,
|
||||
[this](int val) {
|
||||
QString sufix = val == 1 ? tr(" second") : tr(" seconds");
|
||||
this->m_delaySpinBox->setSuffix(sufix);
|
||||
});
|
||||
m_delaySpinBox = new QSpinBox();
|
||||
m_delaySpinBox->setSingleStep(1.0);
|
||||
m_delaySpinBox->setMinimum(0.0);
|
||||
m_delaySpinBox->setMaximum(999.0);
|
||||
m_delaySpinBox->setSpecialValueText(tr("No Delay"));
|
||||
m_delaySpinBox->setMinimumWidth(160);
|
||||
// with QT 5.7 qOverload<int>(&QSpinBox::valueChanged),
|
||||
connect(m_delaySpinBox,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
||||
this,
|
||||
[this](int val) {
|
||||
QString sufix = val == 1 ? tr(" second") : tr(" seconds");
|
||||
this->m_delaySpinBox->setSuffix(sufix);
|
||||
});
|
||||
|
||||
m_launchButton = new QPushButton(tr("Take new screenshot"));
|
||||
m_launchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
connect(m_launchButton,
|
||||
&QPushButton::pressed,
|
||||
this,
|
||||
&CaptureLauncher::startCapture);
|
||||
m_launchButton->setFocus();
|
||||
m_launchButton = new QPushButton(tr("Take new screenshot"));
|
||||
m_launchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
connect(m_launchButton,
|
||||
&QPushButton::pressed,
|
||||
this,
|
||||
&CaptureLauncher::startCapture);
|
||||
m_launchButton->setFocus();
|
||||
|
||||
QFormLayout* captureModeForm = new QFormLayout;
|
||||
captureModeForm->addRow(tr("Area:"), m_captureType);
|
||||
captureModeForm->addRow(tr("Delay:"), m_delaySpinBox);
|
||||
captureModeForm->setContentsMargins(24, 0, 0, 0);
|
||||
QFormLayout* captureModeForm = new QFormLayout;
|
||||
captureModeForm->addRow(tr("Area:"), m_captureType);
|
||||
captureModeForm->addRow(tr("Delay:"), m_delaySpinBox);
|
||||
captureModeForm->setContentsMargins(24, 0, 0, 0);
|
||||
|
||||
m_mainLayout = new QVBoxLayout();
|
||||
m_mainLayout->addStretch(1);
|
||||
m_mainLayout->addWidget(m_CaptureModeLabel);
|
||||
m_mainLayout->addLayout(captureModeForm);
|
||||
m_mainLayout->addStretch(10);
|
||||
m_mainLayout->addWidget(m_launchButton, 1, Qt::AlignCenter);
|
||||
m_mainLayout->setContentsMargins(10, 0, 0, 10);
|
||||
layout->addLayout(m_mainLayout, 0, 1);
|
||||
layout->setColumnMinimumWidth(0, 320);
|
||||
layout->setColumnMinimumWidth(1, 320);
|
||||
m_mainLayout = new QVBoxLayout();
|
||||
m_mainLayout->addStretch(1);
|
||||
m_mainLayout->addWidget(m_CaptureModeLabel);
|
||||
m_mainLayout->addLayout(captureModeForm);
|
||||
m_mainLayout->addStretch(10);
|
||||
m_mainLayout->addWidget(m_launchButton, 1, Qt::AlignCenter);
|
||||
m_mainLayout->setContentsMargins(10, 0, 0, 10);
|
||||
layout->addLayout(m_mainLayout, 0, 1);
|
||||
layout->setColumnMinimumWidth(0, 320);
|
||||
layout->setColumnMinimumWidth(1, 320);
|
||||
}
|
||||
|
||||
// HACK:
|
||||
// https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
|
||||
void
|
||||
CaptureLauncher::startCapture()
|
||||
void CaptureLauncher::startCapture()
|
||||
{
|
||||
hide();
|
||||
auto mode = static_cast<CaptureRequest::CaptureMode>(
|
||||
m_captureType->currentData().toInt());
|
||||
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
|
||||
m_id = req.id();
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
hide();
|
||||
auto mode = static_cast<CaptureRequest::CaptureMode>(
|
||||
m_captureType->currentData().toInt());
|
||||
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
|
||||
m_id = req.id();
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void
|
||||
CaptureLauncher::startDrag()
|
||||
void CaptureLauncher::startDrag()
|
||||
{
|
||||
QDrag* dragHandler = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
mimeData->setImageData(m_imageLabel->pixmap());
|
||||
dragHandler->setMimeData(mimeData);
|
||||
QDrag* dragHandler = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
mimeData->setImageData(m_imageLabel->pixmap());
|
||||
dragHandler->setMimeData(mimeData);
|
||||
|
||||
dragHandler->setPixmap(m_imageLabel->pixmap()->scaled(
|
||||
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
||||
dragHandler->exec();
|
||||
dragHandler->setPixmap(m_imageLabel->pixmap()->scaled(
|
||||
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
||||
dragHandler->exec();
|
||||
}
|
||||
|
||||
void
|
||||
CaptureLauncher::captureTaken(uint id, QPixmap p)
|
||||
void CaptureLauncher::captureTaken(uint id, QPixmap p)
|
||||
{
|
||||
if (id == m_id) {
|
||||
m_id = 0;
|
||||
m_imageLabel->setScreenshot(p);
|
||||
show();
|
||||
}
|
||||
if (id == m_id) {
|
||||
m_id = 0;
|
||||
m_imageLabel->setScreenshot(p);
|
||||
show();
|
||||
}
|
||||
|
||||
auto mode = static_cast<CaptureRequest::CaptureMode>(
|
||||
m_captureType->currentData().toInt());
|
||||
auto mode = static_cast<CaptureRequest::CaptureMode>(
|
||||
m_captureType->currentData().toInt());
|
||||
|
||||
if (mode == CaptureRequest::FULLSCREEN_MODE) {
|
||||
ScreenshotSaver().saveToFilesystemGUI(p);
|
||||
}
|
||||
if (mode == CaptureRequest::FULLSCREEN_MODE) {
|
||||
ScreenshotSaver().saveToFilesystemGUI(p);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CaptureLauncher::captureFailed(uint id)
|
||||
void CaptureLauncher::captureFailed(uint id)
|
||||
{
|
||||
if (id == m_id) {
|
||||
m_id = 0;
|
||||
show();
|
||||
}
|
||||
if (id == m_id) {
|
||||
m_id = 0;
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,22 +29,22 @@ class ImageLabel;
|
||||
|
||||
class CaptureLauncher : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CaptureLauncher(QWidget* parent = nullptr);
|
||||
explicit CaptureLauncher(QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void startCapture();
|
||||
void startDrag();
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureFailed(uint id);
|
||||
void startCapture();
|
||||
void startDrag();
|
||||
void captureTaken(uint id, QPixmap p);
|
||||
void captureFailed(uint id);
|
||||
|
||||
private:
|
||||
QSpinBox* m_delaySpinBox;
|
||||
QComboBox* m_captureType;
|
||||
QVBoxLayout* m_mainLayout;
|
||||
QPushButton* m_launchButton;
|
||||
QLabel* m_CaptureModeLabel;
|
||||
ImageLabel* m_imageLabel;
|
||||
uint m_id;
|
||||
QSpinBox* m_delaySpinBox;
|
||||
QComboBox* m_captureType;
|
||||
QVBoxLayout* m_mainLayout;
|
||||
QPushButton* m_launchButton;
|
||||
QLabel* m_CaptureModeLabel;
|
||||
ImageLabel* m_imageLabel;
|
||||
uint m_id;
|
||||
};
|
||||
|
||||
@@ -22,60 +22,58 @@ DraggableWidgetMaker::DraggableWidgetMaker(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
void
|
||||
DraggableWidgetMaker::makeDraggable(QWidget* widget)
|
||||
void DraggableWidgetMaker::makeDraggable(QWidget* widget)
|
||||
{
|
||||
widget->installEventFilter(this);
|
||||
widget->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool
|
||||
DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
|
||||
bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
auto widget = static_cast<QWidget*>(obj);
|
||||
auto widget = static_cast<QWidget*>(obj);
|
||||
|
||||
// based on https://stackoverflow.com/a/12221360/964478
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseButtonPress: {
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
// based on https://stackoverflow.com/a/12221360/964478
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseButtonPress: {
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
|
||||
m_isPressing = false;
|
||||
m_isDragging = false;
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
m_isPressing = true;
|
||||
m_mousePressPos = mouseEvent->globalPos();
|
||||
m_mouseMovePos = m_mousePressPos;
|
||||
}
|
||||
} break;
|
||||
case QEvent::MouseMove: {
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
m_isPressing = false;
|
||||
m_isDragging = false;
|
||||
if (mouseEvent->button() == Qt::LeftButton) {
|
||||
m_isPressing = true;
|
||||
m_mousePressPos = mouseEvent->globalPos();
|
||||
m_mouseMovePos = m_mousePressPos;
|
||||
}
|
||||
} break;
|
||||
case QEvent::MouseMove: {
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
|
||||
if (m_isPressing) {
|
||||
QPoint widgetPos = widget->mapToGlobal(widget->pos());
|
||||
QPoint eventPos = mouseEvent->globalPos();
|
||||
QPoint diff = eventPos - m_mouseMovePos;
|
||||
QPoint newPos = widgetPos + diff;
|
||||
if (m_isPressing) {
|
||||
QPoint widgetPos = widget->mapToGlobal(widget->pos());
|
||||
QPoint eventPos = mouseEvent->globalPos();
|
||||
QPoint diff = eventPos - m_mouseMovePos;
|
||||
QPoint newPos = widgetPos + diff;
|
||||
|
||||
widget->move(widget->mapFromGlobal(newPos));
|
||||
widget->move(widget->mapFromGlobal(newPos));
|
||||
|
||||
if (!m_isDragging) {
|
||||
QPoint totalMovedDiff = eventPos - m_mousePressPos;
|
||||
if (totalMovedDiff.manhattanLength() > 3) {
|
||||
m_isDragging = true;
|
||||
}
|
||||
}
|
||||
if (!m_isDragging) {
|
||||
QPoint totalMovedDiff = eventPos - m_mousePressPos;
|
||||
if (totalMovedDiff.manhattanLength() > 3) {
|
||||
m_isDragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
m_mouseMovePos = eventPos;
|
||||
}
|
||||
} break;
|
||||
case QEvent::MouseButtonRelease: {
|
||||
if (m_isDragging) {
|
||||
m_isPressing = false;
|
||||
m_isDragging = false;
|
||||
event->ignore();
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
m_mouseMovePos = eventPos;
|
||||
}
|
||||
} break;
|
||||
case QEvent::MouseButtonRelease: {
|
||||
if (m_isDragging) {
|
||||
m_isPressing = false;
|
||||
m_isDragging = false;
|
||||
event->ignore();
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
@@ -24,18 +24,18 @@
|
||||
|
||||
class DraggableWidgetMaker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
DraggableWidgetMaker(QObject* parent = nullptr);
|
||||
DraggableWidgetMaker(QObject* parent = nullptr);
|
||||
|
||||
void makeDraggable(QWidget* widget);
|
||||
void makeDraggable(QWidget* widget);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
bool m_isPressing = false;
|
||||
bool m_isDragging = false;
|
||||
QPoint m_mouseMovePos;
|
||||
QPoint m_mousePressPos;
|
||||
bool m_isPressing = false;
|
||||
bool m_isDragging = false;
|
||||
QPoint m_mouseMovePos;
|
||||
QPoint m_mousePressPos;
|
||||
};
|
||||
|
||||
@@ -24,75 +24,69 @@ ImageLabel::ImageLabel(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
, m_pixmap(QPixmap())
|
||||
{
|
||||
m_DSEffect = new QGraphicsDropShadowEffect(this);
|
||||
m_DSEffect = new QGraphicsDropShadowEffect(this);
|
||||
|
||||
m_DSEffect->setBlurRadius(5);
|
||||
m_DSEffect->setOffset(0);
|
||||
m_DSEffect->setColor(QColor(Qt::black));
|
||||
m_DSEffect->setBlurRadius(5);
|
||||
m_DSEffect->setOffset(0);
|
||||
m_DSEffect->setColor(QColor(Qt::black));
|
||||
|
||||
setGraphicsEffect(m_DSEffect);
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setAlignment(Qt::AlignCenter);
|
||||
setMinimumSize(size());
|
||||
setGraphicsEffect(m_DSEffect);
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setAlignment(Qt::AlignCenter);
|
||||
setMinimumSize(size());
|
||||
}
|
||||
|
||||
void
|
||||
ImageLabel::setScreenshot(const QPixmap& pixmap)
|
||||
void ImageLabel::setScreenshot(const QPixmap& pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
const QString tooltip =
|
||||
QStringLiteral("%1x%2 px").arg(m_pixmap.width()).arg(m_pixmap.height());
|
||||
setToolTip(tooltip);
|
||||
setScaledPixmap();
|
||||
m_pixmap = pixmap;
|
||||
const QString tooltip =
|
||||
QStringLiteral("%1x%2 px").arg(m_pixmap.width()).arg(m_pixmap.height());
|
||||
setToolTip(tooltip);
|
||||
setScaledPixmap();
|
||||
}
|
||||
|
||||
void
|
||||
ImageLabel::setScaledPixmap()
|
||||
void ImageLabel::setScaledPixmap()
|
||||
{
|
||||
const qreal scale = qApp->devicePixelRatio();
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(
|
||||
size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
scaledPixmap.setDevicePixelRatio(scale);
|
||||
setPixmap(scaledPixmap);
|
||||
const qreal scale = qApp->devicePixelRatio();
|
||||
QPixmap scaledPixmap = m_pixmap.scaled(
|
||||
size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
scaledPixmap.setDevicePixelRatio(scale);
|
||||
setPixmap(scaledPixmap);
|
||||
}
|
||||
|
||||
// drag handlers
|
||||
|
||||
void
|
||||
ImageLabel::mousePressEvent(QMouseEvent* event)
|
||||
void ImageLabel::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_dragStartPosition = event->pos();
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
}
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_dragStartPosition = event->pos();
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ImageLabel::mouseReleaseEvent(QMouseEvent* event)
|
||||
void ImageLabel::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageLabel::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!(event->buttons() & Qt::LeftButton)) {
|
||||
return;
|
||||
}
|
||||
if ((event->pos() - m_dragStartPosition).manhattanLength() <
|
||||
QGuiApplication::styleHints()->startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ImageLabel::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!(event->buttons() & Qt::LeftButton)) {
|
||||
return;
|
||||
}
|
||||
if ((event->pos() - m_dragStartPosition).manhattanLength() <
|
||||
QGuiApplication::styleHints()->startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
emit dragInitiated();
|
||||
emit dragInitiated();
|
||||
}
|
||||
|
||||
// resize handler
|
||||
void
|
||||
ImageLabel::resizeEvent(QResizeEvent* event)
|
||||
void ImageLabel::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
setScaledPixmap();
|
||||
Q_UNUSED(event);
|
||||
setScaledPixmap();
|
||||
}
|
||||
|
||||
@@ -31,25 +31,25 @@
|
||||
|
||||
class ImageLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImageLabel(QWidget* parent = nullptr);
|
||||
void setScreenshot(const QPixmap& pixmap);
|
||||
explicit ImageLabel(QWidget* parent = nullptr);
|
||||
void setScreenshot(const QPixmap& pixmap);
|
||||
|
||||
signals:
|
||||
void dragInitiated();
|
||||
void dragInitiated();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
void setScaledPixmap();
|
||||
void setScaledPixmap();
|
||||
|
||||
QGraphicsDropShadowEffect* m_DSEffect;
|
||||
QPixmap m_pixmap;
|
||||
QPoint m_dragStartPosition;
|
||||
QGraphicsDropShadowEffect* m_DSEffect;
|
||||
QPixmap m_pixmap;
|
||||
QPoint m_dragStartPosition;
|
||||
};
|
||||
|
||||
@@ -35,22 +35,22 @@
|
||||
InfoWindow::InfoWindow(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("About"));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
setWindowTitle(tr("About"));
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
QRect position = frameGeometry();
|
||||
QScreen* screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
position.moveCenter(screen->availableGeometry().center());
|
||||
move(position.topLeft());
|
||||
QRect position = frameGeometry();
|
||||
QScreen* screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
position.moveCenter(screen->availableGeometry().center());
|
||||
move(position.topLeft());
|
||||
#endif
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setAlignment(Qt::AlignHCenter);
|
||||
initLabels();
|
||||
initInfoTable();
|
||||
show();
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setAlignment(Qt::AlignHCenter);
|
||||
initLabels();
|
||||
initInfoTable();
|
||||
show();
|
||||
}
|
||||
|
||||
QVector<const char*> InfoWindow::m_keys = { "←↓↑→",
|
||||
@@ -64,94 +64,93 @@ QVector<const char*> InfoWindow::m_keys = { "←↓↑→",
|
||||
QT_TR_NOOP("Mouse Wheel") };
|
||||
|
||||
QVector<const char*> InfoWindow::m_description = {
|
||||
QT_TR_NOOP("Move selection 1px"),
|
||||
QT_TR_NOOP("Resize selection 1px"),
|
||||
QT_TR_NOOP("Quit capture"),
|
||||
QT_TR_NOOP("Copy to clipboard"),
|
||||
QT_TR_NOOP("Save selection as a file"),
|
||||
QT_TR_NOOP("Undo the last modification"),
|
||||
QT_TR_NOOP("Toggle visibility of sidebar with options of the selected tool"),
|
||||
QT_TR_NOOP("Show color picker"),
|
||||
QT_TR_NOOP("Change the tool's thickness")
|
||||
QT_TR_NOOP("Move selection 1px"),
|
||||
QT_TR_NOOP("Resize selection 1px"),
|
||||
QT_TR_NOOP("Quit capture"),
|
||||
QT_TR_NOOP("Copy to clipboard"),
|
||||
QT_TR_NOOP("Save selection as a file"),
|
||||
QT_TR_NOOP("Undo the last modification"),
|
||||
QT_TR_NOOP(
|
||||
"Toggle visibility of sidebar with options of the selected tool"),
|
||||
QT_TR_NOOP("Show color picker"),
|
||||
QT_TR_NOOP("Change the tool's thickness")
|
||||
};
|
||||
|
||||
void
|
||||
InfoWindow::initInfoTable()
|
||||
void InfoWindow::initInfoTable()
|
||||
{
|
||||
QTableWidget* table = new QTableWidget(this);
|
||||
table->setToolTip(tr("Available shortcuts in the screen capture mode."));
|
||||
QTableWidget* table = new QTableWidget(this);
|
||||
table->setToolTip(tr("Available shortcuts in the screen capture mode."));
|
||||
|
||||
m_layout->addWidget(table);
|
||||
m_layout->addWidget(table);
|
||||
|
||||
table->setColumnCount(2);
|
||||
table->setRowCount(m_keys.size());
|
||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
table->setFocusPolicy(Qt::NoFocus);
|
||||
table->verticalHeader()->hide();
|
||||
// header creation
|
||||
QStringList names;
|
||||
names << tr("Key") << tr("Description");
|
||||
table->setHorizontalHeaderLabels(names);
|
||||
table->setColumnCount(2);
|
||||
table->setRowCount(m_keys.size());
|
||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
table->setFocusPolicy(Qt::NoFocus);
|
||||
table->verticalHeader()->hide();
|
||||
// header creation
|
||||
QStringList names;
|
||||
names << tr("Key") << tr("Description");
|
||||
table->setHorizontalHeaderLabels(names);
|
||||
|
||||
// add content
|
||||
for (int i = 0; i < m_keys.size(); ++i) {
|
||||
table->setItem(i, 0, new QTableWidgetItem(tr(m_keys.at(i))));
|
||||
table->setItem(i, 1, new QTableWidgetItem(tr(m_description.at(i))));
|
||||
}
|
||||
|
||||
// Read-only table items
|
||||
for (int x = 0; x < table->rowCount(); ++x) {
|
||||
for (int y = 0; y < table->columnCount(); ++y) {
|
||||
QTableWidgetItem* item = table->item(x, y);
|
||||
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
|
||||
// add content
|
||||
for (int i = 0; i < m_keys.size(); ++i) {
|
||||
table->setItem(i, 0, new QTableWidgetItem(tr(m_keys.at(i))));
|
||||
table->setItem(i, 1, new QTableWidgetItem(tr(m_description.at(i))));
|
||||
}
|
||||
}
|
||||
|
||||
// adjust size
|
||||
table->resizeColumnsToContents();
|
||||
table->resizeRowsToContents();
|
||||
table->setMinimumWidth(400);
|
||||
table->setMaximumWidth(600);
|
||||
// Read-only table items
|
||||
for (int x = 0; x < table->rowCount(); ++x) {
|
||||
for (int y = 0; y < table->columnCount(); ++y) {
|
||||
QTableWidgetItem* item = table->item(x, y);
|
||||
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
|
||||
}
|
||||
}
|
||||
|
||||
table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
table->horizontalHeader()->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Expanding);
|
||||
m_layout->addStretch();
|
||||
// adjust size
|
||||
table->resizeColumnsToContents();
|
||||
table->resizeRowsToContents();
|
||||
table->setMinimumWidth(400);
|
||||
table->setMaximumWidth(600);
|
||||
|
||||
table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
table->horizontalHeader()->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Expanding);
|
||||
m_layout->addStretch();
|
||||
}
|
||||
|
||||
void
|
||||
InfoWindow::initLabels()
|
||||
void InfoWindow::initLabels()
|
||||
{
|
||||
m_layout->addStretch();
|
||||
QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
|
||||
licenseTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(licenseTitleLabel);
|
||||
QLabel* licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this);
|
||||
licenseLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(licenseLabel);
|
||||
m_layout->addStretch();
|
||||
m_layout->addStretch();
|
||||
QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
|
||||
licenseTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(licenseTitleLabel);
|
||||
QLabel* licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this);
|
||||
licenseLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(licenseLabel);
|
||||
m_layout->addStretch();
|
||||
|
||||
QLabel* versionTitleLabel = new QLabel(tr("<u><b>Version</b></u>"), this);
|
||||
versionTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(versionTitleLabel);
|
||||
QLabel* versionTitleLabel = new QLabel(tr("<u><b>Version</b></u>"), this);
|
||||
versionTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(versionTitleLabel);
|
||||
|
||||
QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) +
|
||||
"\nCompiled with Qt " + QT_VERSION_STR;
|
||||
QLabel* versionLabel = new QLabel(versionMsg, this);
|
||||
versionLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(versionLabel);
|
||||
m_layout->addStretch();
|
||||
m_layout->addSpacing(10);
|
||||
QLabel* shortcutsTitleLabel = new QLabel(tr("<u><b>Shortcuts</b></u>"), this);
|
||||
shortcutsTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
;
|
||||
m_layout->addWidget(shortcutsTitleLabel);
|
||||
QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) +
|
||||
"\nCompiled with Qt " + QT_VERSION_STR;
|
||||
QLabel* versionLabel = new QLabel(versionMsg, this);
|
||||
versionLabel->setAlignment(Qt::AlignHCenter);
|
||||
m_layout->addWidget(versionLabel);
|
||||
m_layout->addStretch();
|
||||
m_layout->addSpacing(10);
|
||||
QLabel* shortcutsTitleLabel =
|
||||
new QLabel(tr("<u><b>Shortcuts</b></u>"), this);
|
||||
shortcutsTitleLabel->setAlignment(Qt::AlignHCenter);
|
||||
;
|
||||
m_layout->addWidget(shortcutsTitleLabel);
|
||||
}
|
||||
|
||||
void
|
||||
InfoWindow::keyPressEvent(QKeyEvent* e)
|
||||
void InfoWindow::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
close();
|
||||
}
|
||||
if (e->key() == Qt::Key_Escape) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@ class QVBoxLayout;
|
||||
|
||||
class InfoWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InfoWindow(QWidget* parent = nullptr);
|
||||
explicit InfoWindow(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
|
||||
private:
|
||||
void initInfoTable();
|
||||
void initLabels();
|
||||
QVBoxLayout* m_layout;
|
||||
void initInfoTable();
|
||||
void initLabels();
|
||||
QVBoxLayout* m_layout;
|
||||
|
||||
static QVector<const char*> m_keys;
|
||||
static QVector<const char*> m_description;
|
||||
static QVector<const char*> m_keys;
|
||||
static QVector<const char*> m_description;
|
||||
};
|
||||
|
||||
@@ -29,86 +29,79 @@ LoadSpinner::LoadSpinner(QWidget* parent)
|
||||
, m_span(0)
|
||||
, m_growing(true)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
const int size = QApplication::fontMetrics().height() * 8;
|
||||
setFixedSize(size, size);
|
||||
updateFrame();
|
||||
// init timer
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, &QTimer::timeout, this, &LoadSpinner::rotate);
|
||||
m_timer->setInterval(30);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
const int size = QApplication::fontMetrics().height() * 8;
|
||||
setFixedSize(size, size);
|
||||
updateFrame();
|
||||
// init timer
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, &QTimer::timeout, this, &LoadSpinner::rotate);
|
||||
m_timer->setInterval(30);
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::setColor(const QColor& c)
|
||||
void LoadSpinner::setColor(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
m_color = c;
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::setWidth(int w)
|
||||
void LoadSpinner::setWidth(int w)
|
||||
{
|
||||
setFixedSize(w, w);
|
||||
updateFrame();
|
||||
setFixedSize(w, w);
|
||||
updateFrame();
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::setHeight(int h)
|
||||
void LoadSpinner::setHeight(int h)
|
||||
{
|
||||
setFixedSize(h, h);
|
||||
updateFrame();
|
||||
setFixedSize(h, h);
|
||||
updateFrame();
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::start()
|
||||
void LoadSpinner::start()
|
||||
{
|
||||
m_timer->start();
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::stop()
|
||||
void LoadSpinner::stop()
|
||||
{
|
||||
m_timer->stop();
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::paintEvent(QPaintEvent*)
|
||||
void LoadSpinner::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
auto pen = QPen(m_color);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
auto pen = QPen(m_color);
|
||||
|
||||
pen.setWidth(height() / 10);
|
||||
painter.setPen(pen);
|
||||
painter.setOpacity(0.2);
|
||||
painter.drawArc(m_frame, 0, 5760);
|
||||
painter.setOpacity(1.0);
|
||||
painter.drawArc(m_frame, (m_startAngle * 16), (m_span * 16));
|
||||
pen.setWidth(height() / 10);
|
||||
painter.setPen(pen);
|
||||
painter.setOpacity(0.2);
|
||||
painter.drawArc(m_frame, 0, 5760);
|
||||
painter.setOpacity(1.0);
|
||||
painter.drawArc(m_frame, (m_startAngle * 16), (m_span * 16));
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::rotate()
|
||||
void LoadSpinner::rotate()
|
||||
{
|
||||
const int advance = 3;
|
||||
const int grow = 8;
|
||||
if (m_growing) {
|
||||
m_startAngle = (m_startAngle + advance) % 360;
|
||||
m_span += grow;
|
||||
if (m_span > 260) {
|
||||
m_growing = false;
|
||||
const int advance = 3;
|
||||
const int grow = 8;
|
||||
if (m_growing) {
|
||||
m_startAngle = (m_startAngle + advance) % 360;
|
||||
m_span += grow;
|
||||
if (m_span > 260) {
|
||||
m_growing = false;
|
||||
}
|
||||
} else {
|
||||
m_startAngle = (m_startAngle + grow) % 360;
|
||||
m_span = m_span + advance - grow;
|
||||
if (m_span < 10) {
|
||||
m_growing = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_startAngle = (m_startAngle + grow) % 360;
|
||||
m_span = m_span + advance - grow;
|
||||
if (m_span < 10) {
|
||||
m_growing = true;
|
||||
}
|
||||
}
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
LoadSpinner::updateFrame()
|
||||
void LoadSpinner::updateFrame()
|
||||
{
|
||||
m_frame = QRect(OFFSET, OFFSET, width() - OFFSET * 2, height() - OFFSET * 2);
|
||||
m_frame =
|
||||
QRect(OFFSET, OFFSET, width() - OFFSET * 2, height() - OFFSET * 2);
|
||||
}
|
||||
|
||||
@@ -21,30 +21,30 @@
|
||||
|
||||
class LoadSpinner : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoadSpinner(QWidget* parent = nullptr);
|
||||
explicit LoadSpinner(QWidget* parent = nullptr);
|
||||
|
||||
void setColor(const QColor& c);
|
||||
void setWidth(int w);
|
||||
void setHeight(int h);
|
||||
void start();
|
||||
void stop();
|
||||
void setColor(const QColor& c);
|
||||
void setWidth(int w);
|
||||
void setHeight(int h);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*);
|
||||
void paintEvent(QPaintEvent*);
|
||||
|
||||
private slots:
|
||||
void rotate();
|
||||
void rotate();
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
QTimer* m_timer;
|
||||
QColor m_color;
|
||||
QTimer* m_timer;
|
||||
|
||||
int m_startAngle = 0;
|
||||
int m_span = 180;
|
||||
bool m_growing;
|
||||
int m_startAngle = 0;
|
||||
int m_span = 180;
|
||||
bool m_growing;
|
||||
|
||||
QRect m_frame;
|
||||
void updateFrame();
|
||||
QRect m_frame;
|
||||
void updateFrame();
|
||||
};
|
||||
|
||||
@@ -26,55 +26,52 @@
|
||||
NotificationWidget::NotificationWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(7000);
|
||||
connect(m_timer, &QTimer::timeout, this, &NotificationWidget::animatedHide);
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(7000);
|
||||
connect(m_timer, &QTimer::timeout, this, &NotificationWidget::animatedHide);
|
||||
|
||||
m_content = new QFrame();
|
||||
m_layout = new QVBoxLayout();
|
||||
m_label = new QLabel(m_content);
|
||||
m_label->hide();
|
||||
m_content = new QFrame();
|
||||
m_layout = new QVBoxLayout();
|
||||
m_label = new QLabel(m_content);
|
||||
m_label->hide();
|
||||
|
||||
m_showAnimation = new QPropertyAnimation(m_content, "geometry", this);
|
||||
m_showAnimation->setDuration(300);
|
||||
m_showAnimation = new QPropertyAnimation(m_content, "geometry", this);
|
||||
m_showAnimation->setDuration(300);
|
||||
|
||||
m_hideAnimation = new QPropertyAnimation(m_content, "geometry", this);
|
||||
m_hideAnimation->setDuration(300);
|
||||
connect(
|
||||
m_hideAnimation, &QPropertyAnimation::finished, m_label, &QLabel::hide);
|
||||
m_hideAnimation = new QPropertyAnimation(m_content, "geometry", this);
|
||||
m_hideAnimation->setDuration(300);
|
||||
connect(
|
||||
m_hideAnimation, &QPropertyAnimation::finished, m_label, &QLabel::hide);
|
||||
|
||||
auto mainLayout = new QVBoxLayout();
|
||||
setLayout(mainLayout);
|
||||
auto mainLayout = new QVBoxLayout();
|
||||
setLayout(mainLayout);
|
||||
|
||||
mainLayout->addWidget(m_content);
|
||||
m_layout->addWidget(m_label, 0, Qt::AlignHCenter);
|
||||
m_content->setLayout(m_layout);
|
||||
mainLayout->addWidget(m_content);
|
||||
m_layout->addWidget(m_label, 0, Qt::AlignHCenter);
|
||||
m_content->setLayout(m_layout);
|
||||
|
||||
setFixedHeight(40);
|
||||
setFixedHeight(40);
|
||||
}
|
||||
|
||||
void
|
||||
NotificationWidget::showMessage(const QString& msg)
|
||||
void NotificationWidget::showMessage(const QString& msg)
|
||||
{
|
||||
m_label->setText(msg);
|
||||
m_label->show();
|
||||
animatedShow();
|
||||
m_label->setText(msg);
|
||||
m_label->show();
|
||||
animatedShow();
|
||||
}
|
||||
|
||||
void
|
||||
NotificationWidget::animatedShow()
|
||||
void NotificationWidget::animatedShow()
|
||||
{
|
||||
m_showAnimation->setStartValue(QRect(0, 0, width(), 0));
|
||||
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
|
||||
m_showAnimation->start();
|
||||
m_timer->start();
|
||||
m_showAnimation->setStartValue(QRect(0, 0, width(), 0));
|
||||
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
|
||||
m_showAnimation->start();
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
void
|
||||
NotificationWidget::animatedHide()
|
||||
void NotificationWidget::animatedHide()
|
||||
{
|
||||
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
|
||||
m_hideAnimation->setEndValue(QRect(0, 0, width(), 0));
|
||||
m_hideAnimation->start();
|
||||
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
|
||||
m_hideAnimation->setEndValue(QRect(0, 0, width(), 0));
|
||||
m_hideAnimation->start();
|
||||
}
|
||||
|
||||
@@ -27,20 +27,20 @@ class QFrame;
|
||||
|
||||
class NotificationWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NotificationWidget(QWidget* parent = nullptr);
|
||||
explicit NotificationWidget(QWidget* parent = nullptr);
|
||||
|
||||
void showMessage(const QString& msg);
|
||||
void showMessage(const QString& msg);
|
||||
|
||||
private:
|
||||
QLabel* m_label;
|
||||
QPropertyAnimation* m_showAnimation;
|
||||
QPropertyAnimation* m_hideAnimation;
|
||||
QVBoxLayout* m_layout;
|
||||
QFrame* m_content;
|
||||
QTimer* m_timer;
|
||||
QLabel* m_label;
|
||||
QPropertyAnimation* m_showAnimation;
|
||||
QPropertyAnimation* m_hideAnimation;
|
||||
QVBoxLayout* m_layout;
|
||||
QFrame* m_content;
|
||||
QTimer* m_timer;
|
||||
|
||||
void animatedShow();
|
||||
void animatedHide();
|
||||
void animatedShow();
|
||||
void animatedHide();
|
||||
};
|
||||
|
||||
@@ -37,51 +37,47 @@ OrientablePushButton::OrientablePushButton(const QIcon& icon,
|
||||
: CaptureButton(icon, text, parent)
|
||||
{}
|
||||
|
||||
QSize
|
||||
OrientablePushButton::sizeHint() const
|
||||
QSize OrientablePushButton::sizeHint() const
|
||||
{
|
||||
QSize sh = QPushButton::sizeHint();
|
||||
QSize sh = QPushButton::sizeHint();
|
||||
|
||||
if (m_orientation != OrientablePushButton::Horizontal) {
|
||||
sh.transpose();
|
||||
}
|
||||
if (m_orientation != OrientablePushButton::Horizontal) {
|
||||
sh.transpose();
|
||||
}
|
||||
|
||||
return sh;
|
||||
return sh;
|
||||
}
|
||||
|
||||
void
|
||||
OrientablePushButton::paintEvent(QPaintEvent* event)
|
||||
void OrientablePushButton::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(event)
|
||||
|
||||
QStylePainter painter(this);
|
||||
QStyleOptionButton option;
|
||||
initStyleOption(&option);
|
||||
QStylePainter painter(this);
|
||||
QStyleOptionButton option;
|
||||
initStyleOption(&option);
|
||||
|
||||
if (m_orientation == OrientablePushButton::VerticalTopToBottom) {
|
||||
painter.rotate(90);
|
||||
painter.translate(0, -1 * width());
|
||||
option.rect = option.rect.transposed();
|
||||
}
|
||||
if (m_orientation == OrientablePushButton::VerticalTopToBottom) {
|
||||
painter.rotate(90);
|
||||
painter.translate(0, -1 * width());
|
||||
option.rect = option.rect.transposed();
|
||||
}
|
||||
|
||||
else if (m_orientation == OrientablePushButton::VerticalBottomToTop) {
|
||||
painter.rotate(-90);
|
||||
painter.translate(-1 * height(), 0);
|
||||
option.rect = option.rect.transposed();
|
||||
}
|
||||
else if (m_orientation == OrientablePushButton::VerticalBottomToTop) {
|
||||
painter.rotate(-90);
|
||||
painter.translate(-1 * height(), 0);
|
||||
option.rect = option.rect.transposed();
|
||||
}
|
||||
|
||||
painter.drawControl(QStyle::CE_PushButton, option);
|
||||
painter.drawControl(QStyle::CE_PushButton, option);
|
||||
}
|
||||
|
||||
OrientablePushButton::Orientation
|
||||
OrientablePushButton::orientation() const
|
||||
OrientablePushButton::Orientation OrientablePushButton::orientation() const
|
||||
{
|
||||
return m_orientation;
|
||||
return m_orientation;
|
||||
}
|
||||
|
||||
void
|
||||
OrientablePushButton::setOrientation(
|
||||
void OrientablePushButton::setOrientation(
|
||||
const OrientablePushButton::Orientation& orientation)
|
||||
{
|
||||
m_orientation = orientation;
|
||||
m_orientation = orientation;
|
||||
}
|
||||
|
||||
@@ -24,29 +24,29 @@
|
||||
|
||||
class OrientablePushButton : public CaptureButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Orientation
|
||||
{
|
||||
Horizontal,
|
||||
VerticalTopToBottom,
|
||||
VerticalBottomToTop
|
||||
};
|
||||
enum Orientation
|
||||
{
|
||||
Horizontal,
|
||||
VerticalTopToBottom,
|
||||
VerticalBottomToTop
|
||||
};
|
||||
|
||||
OrientablePushButton(QWidget* parent = nullptr);
|
||||
OrientablePushButton(const QString& text, QWidget* parent = nullptr);
|
||||
OrientablePushButton(const QIcon& icon,
|
||||
const QString& text,
|
||||
QWidget* parent = nullptr);
|
||||
OrientablePushButton(QWidget* parent = nullptr);
|
||||
OrientablePushButton(const QString& text, QWidget* parent = nullptr);
|
||||
OrientablePushButton(const QIcon& icon,
|
||||
const QString& text,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize sizeHint() const;
|
||||
|
||||
OrientablePushButton::Orientation orientation() const;
|
||||
void setOrientation(const OrientablePushButton::Orientation& orientation);
|
||||
OrientablePushButton::Orientation orientation() const;
|
||||
void setOrientation(const OrientablePushButton::Orientation& orientation);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
Orientation m_orientation = Horizontal;
|
||||
Orientation m_orientation = Horizontal;
|
||||
};
|
||||
|
||||
@@ -28,30 +28,31 @@
|
||||
class QColorPickingEventFilter : public QObject
|
||||
{
|
||||
public:
|
||||
explicit QColorPickingEventFilter(SidePanelWidget* pw,
|
||||
QObject* parent = nullptr)
|
||||
: QObject(parent)
|
||||
, m_pw(pw)
|
||||
{}
|
||||
explicit QColorPickingEventFilter(SidePanelWidget* pw,
|
||||
QObject* parent = nullptr)
|
||||
: QObject(parent)
|
||||
, m_pw(pw)
|
||||
{}
|
||||
|
||||
bool eventFilter(QObject*, QEvent* event) override
|
||||
{
|
||||
event->accept();
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
return m_pw->handleMouseMove(static_cast<QMouseEvent*>(event));
|
||||
case QEvent::MouseButtonPress:
|
||||
return m_pw->handleMouseButtonPressed(static_cast<QMouseEvent*>(event));
|
||||
case QEvent::KeyPress:
|
||||
return m_pw->handleKeyPress(static_cast<QKeyEvent*>(event));
|
||||
default:
|
||||
break;
|
||||
bool eventFilter(QObject*, QEvent* event) override
|
||||
{
|
||||
event->accept();
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
return m_pw->handleMouseMove(static_cast<QMouseEvent*>(event));
|
||||
case QEvent::MouseButtonPress:
|
||||
return m_pw->handleMouseButtonPressed(
|
||||
static_cast<QMouseEvent*>(event));
|
||||
case QEvent::KeyPress:
|
||||
return m_pw->handleKeyPress(static_cast<QKeyEvent*>(event));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
SidePanelWidget* m_pw;
|
||||
SidePanelWidget* m_pw;
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
@@ -61,161 +62,150 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
|
||||
, m_pixmap(p)
|
||||
, m_eventFilter(nullptr)
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout = new QVBoxLayout(this);
|
||||
|
||||
QFormLayout* colorForm = new QFormLayout();
|
||||
m_thicknessSlider = new QSlider(Qt::Horizontal);
|
||||
m_thicknessSlider->setValue(m_thickness);
|
||||
m_colorLabel = new QLabel();
|
||||
m_colorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
colorForm->addRow(tr("Active thickness:"), m_thicknessSlider);
|
||||
colorForm->addRow(tr("Active color:"), m_colorLabel);
|
||||
m_layout->addLayout(colorForm);
|
||||
QFormLayout* colorForm = new QFormLayout();
|
||||
m_thicknessSlider = new QSlider(Qt::Horizontal);
|
||||
m_thicknessSlider->setValue(m_thickness);
|
||||
m_colorLabel = new QLabel();
|
||||
m_colorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
colorForm->addRow(tr("Active thickness:"), m_thicknessSlider);
|
||||
colorForm->addRow(tr("Active color:"), m_colorLabel);
|
||||
m_layout->addLayout(colorForm);
|
||||
|
||||
connect(m_thicknessSlider,
|
||||
&QSlider::sliderReleased,
|
||||
this,
|
||||
&SidePanelWidget::updateCurrentThickness);
|
||||
connect(this,
|
||||
&SidePanelWidget::thicknessChanged,
|
||||
this,
|
||||
&SidePanelWidget::updateThickness);
|
||||
connect(m_thicknessSlider,
|
||||
&QSlider::sliderReleased,
|
||||
this,
|
||||
&SidePanelWidget::updateCurrentThickness);
|
||||
connect(this,
|
||||
&SidePanelWidget::thicknessChanged,
|
||||
this,
|
||||
&SidePanelWidget::updateThickness);
|
||||
|
||||
QColor background = this->palette().window().color();
|
||||
bool isDark = ColorUtils::colorIsDark(background);
|
||||
QString modifier =
|
||||
isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
|
||||
QIcon grabIcon(modifier + "colorize.svg");
|
||||
m_colorGrabButton = new QPushButton(grabIcon, QLatin1String(""));
|
||||
updateGrabButton(false);
|
||||
connect(m_colorGrabButton,
|
||||
&QPushButton::pressed,
|
||||
this,
|
||||
&SidePanelWidget::colorGrabberActivated);
|
||||
m_layout->addWidget(m_colorGrabButton);
|
||||
QColor background = this->palette().window().color();
|
||||
bool isDark = ColorUtils::colorIsDark(background);
|
||||
QString modifier =
|
||||
isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
|
||||
QIcon grabIcon(modifier + "colorize.svg");
|
||||
m_colorGrabButton = new QPushButton(grabIcon, QLatin1String(""));
|
||||
updateGrabButton(false);
|
||||
connect(m_colorGrabButton,
|
||||
&QPushButton::pressed,
|
||||
this,
|
||||
&SidePanelWidget::colorGrabberActivated);
|
||||
m_layout->addWidget(m_colorGrabButton);
|
||||
|
||||
m_colorWheel = new color_widgets::ColorWheel(this);
|
||||
m_colorWheel->setColor(m_color);
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::mouseReleaseOnColor,
|
||||
this,
|
||||
&SidePanelWidget::colorChanged);
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::colorChanged,
|
||||
this,
|
||||
&SidePanelWidget::updateColorNoWheel);
|
||||
m_layout->addWidget(m_colorWheel);
|
||||
m_colorWheel = new color_widgets::ColorWheel(this);
|
||||
m_colorWheel->setColor(m_color);
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::mouseReleaseOnColor,
|
||||
this,
|
||||
&SidePanelWidget::colorChanged);
|
||||
connect(m_colorWheel,
|
||||
&color_widgets::ColorWheel::colorChanged,
|
||||
this,
|
||||
&SidePanelWidget::updateColorNoWheel);
|
||||
m_layout->addWidget(m_colorWheel);
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::updateColor(const QColor& c)
|
||||
void SidePanelWidget::updateColor(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
m_colorLabel->setStyleSheet(
|
||||
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
|
||||
m_colorWheel->setColor(m_color);
|
||||
m_color = c;
|
||||
m_colorLabel->setStyleSheet(
|
||||
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
|
||||
m_colorWheel->setColor(m_color);
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::updateThickness(const int& t)
|
||||
void SidePanelWidget::updateThickness(const int& t)
|
||||
{
|
||||
m_thickness = qBound(0, t, 100);
|
||||
m_thicknessSlider->setValue(m_thickness);
|
||||
m_thickness = qBound(0, t, 100);
|
||||
m_thicknessSlider->setValue(m_thickness);
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::updateColorNoWheel(const QColor& c)
|
||||
void SidePanelWidget::updateColorNoWheel(const QColor& c)
|
||||
{
|
||||
m_color = c;
|
||||
m_colorLabel->setStyleSheet(
|
||||
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
|
||||
m_color = c;
|
||||
m_colorLabel->setStyleSheet(
|
||||
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::updateCurrentThickness()
|
||||
void SidePanelWidget::updateCurrentThickness()
|
||||
{
|
||||
emit thicknessChanged(m_thicknessSlider->value());
|
||||
emit thicknessChanged(m_thicknessSlider->value());
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::colorGrabberActivated()
|
||||
void SidePanelWidget::colorGrabberActivated()
|
||||
{
|
||||
grabKeyboard();
|
||||
grabMouse(Qt::CrossCursor);
|
||||
setMouseTracking(true);
|
||||
m_colorBackup = m_color;
|
||||
if (!m_eventFilter) {
|
||||
m_eventFilter = new QColorPickingEventFilter(this, this);
|
||||
}
|
||||
installEventFilter(m_eventFilter);
|
||||
updateGrabButton(true);
|
||||
grabKeyboard();
|
||||
grabMouse(Qt::CrossCursor);
|
||||
setMouseTracking(true);
|
||||
m_colorBackup = m_color;
|
||||
if (!m_eventFilter) {
|
||||
m_eventFilter = new QColorPickingEventFilter(this, this);
|
||||
}
|
||||
installEventFilter(m_eventFilter);
|
||||
updateGrabButton(true);
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::releaseColorGrab()
|
||||
void SidePanelWidget::releaseColorGrab()
|
||||
{
|
||||
setMouseTracking(false);
|
||||
removeEventFilter(m_eventFilter);
|
||||
releaseMouse();
|
||||
releaseKeyboard();
|
||||
setFocus();
|
||||
updateGrabButton(false);
|
||||
setMouseTracking(false);
|
||||
removeEventFilter(m_eventFilter);
|
||||
releaseMouse();
|
||||
releaseKeyboard();
|
||||
setFocus();
|
||||
updateGrabButton(false);
|
||||
}
|
||||
|
||||
QColor
|
||||
SidePanelWidget::grabPixmapColor(const QPoint& p)
|
||||
QColor SidePanelWidget::grabPixmapColor(const QPoint& p)
|
||||
{
|
||||
QColor c;
|
||||
if (m_pixmap) {
|
||||
QPixmap pixel = m_pixmap->copy(QRect(p, p));
|
||||
c = pixel.toImage().pixel(0, 0);
|
||||
}
|
||||
return c;
|
||||
QColor c;
|
||||
if (m_pixmap) {
|
||||
QPixmap pixel = m_pixmap->copy(QRect(p, p));
|
||||
c = pixel.toImage().pixel(0, 0);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
bool
|
||||
SidePanelWidget::handleKeyPress(QKeyEvent* e)
|
||||
bool SidePanelWidget::handleKeyPress(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Space) {
|
||||
emit togglePanel();
|
||||
} else if (e->key() == Qt::Key_Escape) {
|
||||
releaseColorGrab();
|
||||
updateColor(m_colorBackup);
|
||||
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||
updateColor(grabPixmapColor(QCursor::pos()));
|
||||
if (e->key() == Qt::Key_Space) {
|
||||
emit togglePanel();
|
||||
} else if (e->key() == Qt::Key_Escape) {
|
||||
releaseColorGrab();
|
||||
updateColor(m_colorBackup);
|
||||
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||
updateColor(grabPixmapColor(QCursor::pos()));
|
||||
releaseColorGrab();
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
|
||||
{
|
||||
if (m_colorGrabButton->geometry().contains(e->pos()) ||
|
||||
e->button() == Qt::RightButton) {
|
||||
updateColorNoWheel(m_colorBackup);
|
||||
} else if (e->button() == Qt::LeftButton) {
|
||||
updateColor(grabPixmapColor(QCursor::pos()));
|
||||
}
|
||||
releaseColorGrab();
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
|
||||
bool SidePanelWidget::handleMouseMove(QMouseEvent* e)
|
||||
{
|
||||
if (m_colorGrabButton->geometry().contains(e->pos()) ||
|
||||
e->button() == Qt::RightButton) {
|
||||
updateColorNoWheel(m_colorBackup);
|
||||
} else if (e->button() == Qt::LeftButton) {
|
||||
updateColor(grabPixmapColor(QCursor::pos()));
|
||||
}
|
||||
releaseColorGrab();
|
||||
emit colorChanged(m_color);
|
||||
return true;
|
||||
updateColorNoWheel(grabPixmapColor(e->globalPos()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SidePanelWidget::handleMouseMove(QMouseEvent* e)
|
||||
void SidePanelWidget::updateGrabButton(const bool activated)
|
||||
{
|
||||
updateColorNoWheel(grabPixmapColor(e->globalPos()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
SidePanelWidget::updateGrabButton(const bool activated)
|
||||
{
|
||||
if (activated) {
|
||||
m_colorGrabButton->setText(tr("Press ESC to cancel"));
|
||||
} else {
|
||||
m_colorGrabButton->setText(tr("Grab Color"));
|
||||
}
|
||||
if (activated) {
|
||||
m_colorGrabButton->setText(tr("Press ESC to cancel"));
|
||||
} else {
|
||||
m_colorGrabButton->setText(tr("Grab Color"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,47 +28,47 @@ class QSlider;
|
||||
|
||||
class SidePanelWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
friend class QColorPickingEventFilter;
|
||||
friend class QColorPickingEventFilter;
|
||||
|
||||
public:
|
||||
explicit SidePanelWidget(QPixmap* p, QWidget* parent = nullptr);
|
||||
explicit SidePanelWidget(QPixmap* p, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void colorChanged(const QColor& c);
|
||||
void thicknessChanged(const int& t);
|
||||
void togglePanel();
|
||||
void colorChanged(const QColor& c);
|
||||
void thicknessChanged(const int& t);
|
||||
void togglePanel();
|
||||
|
||||
public slots:
|
||||
void updateColor(const QColor& c);
|
||||
void updateThickness(const int& t);
|
||||
void updateColor(const QColor& c);
|
||||
void updateThickness(const int& t);
|
||||
|
||||
private slots:
|
||||
void updateColorNoWheel(const QColor& c);
|
||||
void updateCurrentThickness();
|
||||
void updateColorNoWheel(const QColor& c);
|
||||
void updateCurrentThickness();
|
||||
|
||||
private slots:
|
||||
void colorGrabberActivated();
|
||||
void releaseColorGrab();
|
||||
void colorGrabberActivated();
|
||||
void releaseColorGrab();
|
||||
|
||||
private:
|
||||
QColor grabPixmapColor(const QPoint& p);
|
||||
QColor grabPixmapColor(const QPoint& p);
|
||||
|
||||
bool handleKeyPress(QKeyEvent* e);
|
||||
bool handleMouseButtonPressed(QMouseEvent* e);
|
||||
bool handleMouseMove(QMouseEvent* e);
|
||||
bool handleKeyPress(QKeyEvent* e);
|
||||
bool handleMouseButtonPressed(QMouseEvent* e);
|
||||
bool handleMouseMove(QMouseEvent* e);
|
||||
|
||||
void updateGrabButton(const bool activated);
|
||||
void updateGrabButton(const bool activated);
|
||||
|
||||
QVBoxLayout* m_layout;
|
||||
QPushButton* m_colorGrabButton;
|
||||
color_widgets::ColorWheel* m_colorWheel;
|
||||
QLabel* m_colorLabel;
|
||||
QPixmap* m_pixmap;
|
||||
QColor m_colorBackup;
|
||||
QColor m_color;
|
||||
QSlider* m_thicknessSlider;
|
||||
int m_thickness;
|
||||
QColorPickingEventFilter* m_eventFilter;
|
||||
QVBoxLayout* m_layout;
|
||||
QPushButton* m_colorGrabButton;
|
||||
color_widgets::ColorWheel* m_colorWheel;
|
||||
QLabel* m_colorLabel;
|
||||
QPixmap* m_pixmap;
|
||||
QColor m_colorBackup;
|
||||
QColor m_color;
|
||||
QSlider* m_thicknessSlider;
|
||||
int m_thickness;
|
||||
QColorPickingEventFilter* m_eventFilter;
|
||||
};
|
||||
|
||||
@@ -26,98 +26,93 @@
|
||||
UtilityPanel::UtilityPanel(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
initInternalPanel();
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
||||
m_showAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
|
||||
m_showAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_showAnimation->setDuration(300);
|
||||
|
||||
m_hideAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
|
||||
m_hideAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_hideAnimation->setDuration(300);
|
||||
|
||||
connect(m_hideAnimation,
|
||||
&QPropertyAnimation::finished,
|
||||
m_internalPanel,
|
||||
&QWidget::hide);
|
||||
}
|
||||
|
||||
QWidget*
|
||||
UtilityPanel::toolWidget() const
|
||||
{
|
||||
return m_toolWidget;
|
||||
}
|
||||
|
||||
void
|
||||
UtilityPanel::addToolWidget(QWidget* w)
|
||||
{
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->deleteLater();
|
||||
}
|
||||
if (w) {
|
||||
m_toolWidget = w;
|
||||
m_toolWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
||||
m_upLayout->addWidget(w);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UtilityPanel::clearToolWidget()
|
||||
{
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UtilityPanel::pushWidget(QWidget* w)
|
||||
{
|
||||
m_layout->insertWidget(m_layout->count() - 1, w);
|
||||
}
|
||||
|
||||
void
|
||||
UtilityPanel::toggle()
|
||||
{
|
||||
if (m_internalPanel->isHidden()) {
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, false);
|
||||
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
|
||||
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
|
||||
m_internalPanel->show();
|
||||
m_showAnimation->start();
|
||||
} else {
|
||||
initInternalPanel();
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
|
||||
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
|
||||
m_hideAnimation->start();
|
||||
}
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
||||
m_showAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
|
||||
m_showAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_showAnimation->setDuration(300);
|
||||
|
||||
m_hideAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
|
||||
m_hideAnimation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
m_hideAnimation->setDuration(300);
|
||||
|
||||
connect(m_hideAnimation,
|
||||
&QPropertyAnimation::finished,
|
||||
m_internalPanel,
|
||||
&QWidget::hide);
|
||||
}
|
||||
|
||||
void
|
||||
UtilityPanel::initInternalPanel()
|
||||
QWidget* UtilityPanel::toolWidget() const
|
||||
{
|
||||
m_internalPanel = new QScrollArea(this);
|
||||
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
|
||||
QWidget* widget = new QWidget();
|
||||
m_internalPanel->setWidget(widget);
|
||||
m_internalPanel->setWidgetResizable(true);
|
||||
|
||||
m_layout = new QVBoxLayout();
|
||||
m_upLayout = new QVBoxLayout();
|
||||
m_bottomLayout = new QVBoxLayout();
|
||||
m_layout->addLayout(m_upLayout);
|
||||
m_layout->addLayout(m_bottomLayout);
|
||||
widget->setLayout(m_layout);
|
||||
|
||||
QPushButton* closeButton = new QPushButton(this);
|
||||
closeButton->setText(tr("Close"));
|
||||
connect(closeButton, &QPushButton::clicked, this, &UtilityPanel::toggle);
|
||||
m_bottomLayout->addWidget(closeButton);
|
||||
|
||||
QColor bgColor = palette().window().color();
|
||||
bgColor.setAlphaF(0.0);
|
||||
m_internalPanel->setStyleSheet(
|
||||
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));
|
||||
m_internalPanel->hide();
|
||||
return m_toolWidget;
|
||||
}
|
||||
|
||||
void UtilityPanel::addToolWidget(QWidget* w)
|
||||
{
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->deleteLater();
|
||||
}
|
||||
if (w) {
|
||||
m_toolWidget = w;
|
||||
m_toolWidget->setSizePolicy(QSizePolicy::Ignored,
|
||||
QSizePolicy::Preferred);
|
||||
m_upLayout->addWidget(w);
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityPanel::clearToolWidget()
|
||||
{
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityPanel::pushWidget(QWidget* w)
|
||||
{
|
||||
m_layout->insertWidget(m_layout->count() - 1, w);
|
||||
}
|
||||
|
||||
void UtilityPanel::toggle()
|
||||
{
|
||||
if (m_internalPanel->isHidden()) {
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, false);
|
||||
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
|
||||
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
|
||||
m_internalPanel->show();
|
||||
m_showAnimation->start();
|
||||
} else {
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
|
||||
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
|
||||
m_hideAnimation->start();
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityPanel::initInternalPanel()
|
||||
{
|
||||
m_internalPanel = new QScrollArea(this);
|
||||
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
|
||||
QWidget* widget = new QWidget();
|
||||
m_internalPanel->setWidget(widget);
|
||||
m_internalPanel->setWidgetResizable(true);
|
||||
|
||||
m_layout = new QVBoxLayout();
|
||||
m_upLayout = new QVBoxLayout();
|
||||
m_bottomLayout = new QVBoxLayout();
|
||||
m_layout->addLayout(m_upLayout);
|
||||
m_layout->addLayout(m_bottomLayout);
|
||||
widget->setLayout(m_layout);
|
||||
|
||||
QPushButton* closeButton = new QPushButton(this);
|
||||
closeButton->setText(tr("Close"));
|
||||
connect(closeButton, &QPushButton::clicked, this, &UtilityPanel::toggle);
|
||||
m_bottomLayout->addWidget(closeButton);
|
||||
|
||||
QColor bgColor = palette().window().color();
|
||||
bgColor.setAlphaF(0.0);
|
||||
m_internalPanel->setStyleSheet(
|
||||
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));
|
||||
m_internalPanel->hide();
|
||||
}
|
||||
|
||||
@@ -26,30 +26,30 @@ class QScrollArea;
|
||||
|
||||
class UtilityPanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UtilityPanel(QWidget* parent = nullptr);
|
||||
explicit UtilityPanel(QWidget* parent = nullptr);
|
||||
|
||||
QWidget* toolWidget() const;
|
||||
void addToolWidget(QWidget* w);
|
||||
void clearToolWidget();
|
||||
void pushWidget(QWidget* w);
|
||||
QWidget* toolWidget() const;
|
||||
void addToolWidget(QWidget* w);
|
||||
void clearToolWidget();
|
||||
void pushWidget(QWidget* w);
|
||||
|
||||
signals:
|
||||
void mouseEnter();
|
||||
void mouseLeave();
|
||||
void mouseEnter();
|
||||
void mouseLeave();
|
||||
|
||||
public slots:
|
||||
void toggle();
|
||||
void toggle();
|
||||
|
||||
private:
|
||||
void initInternalPanel();
|
||||
void initInternalPanel();
|
||||
|
||||
QPointer<QWidget> m_toolWidget;
|
||||
QScrollArea* m_internalPanel;
|
||||
QVBoxLayout* m_upLayout;
|
||||
QVBoxLayout* m_bottomLayout;
|
||||
QVBoxLayout* m_layout;
|
||||
QPropertyAnimation* m_showAnimation;
|
||||
QPropertyAnimation* m_hideAnimation;
|
||||
QPointer<QWidget> m_toolWidget;
|
||||
QScrollArea* m_internalPanel;
|
||||
QVBoxLayout* m_upLayout;
|
||||
QVBoxLayout* m_bottomLayout;
|
||||
QVBoxLayout* m_layout;
|
||||
QPropertyAnimation* m_showAnimation;
|
||||
QPropertyAnimation* m_hideAnimation;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user