Add comments and better format of the code

This commit is contained in:
lupoDharkael
2017-05-14 02:04:10 +02:00
parent 811c714a81
commit ae19e5f13e
10 changed files with 42 additions and 41 deletions

View File

@@ -51,8 +51,10 @@ Button::Button(Type t, QWidget *parent) : QPushButton(parent) {
}
// getIcon returns the icon for the type of button, this method lets
// you choose between black or white icons (needed for the config menu)
QIcon Button::getIcon(const Type t, bool isWhite) {
QString iconColor = "Black"; // or "Black"
QString iconColor = "Black";
if (isWhite) {
iconColor = "White";
}
@@ -117,9 +119,9 @@ QIcon Button::getIcon(const Type t, bool isWhite) {
}
return QIcon(path);
}
// get icon returns the icon for the type of button
QIcon Button::getIcon(const Type t) {
// assign th isWhite based on the settings
// assign the isWhite based on the settings
bool isWhite = true;
return getIcon(t, isWhite);
}
@@ -135,7 +137,6 @@ void Button::leaveEvent(QEvent *e) {
}
void Button::mouseReleaseEvent(QMouseEvent *) {
if (m_buttonType == Type::mouseVisibility) {
QSettings settings;
bool mouseVisible = settings.value("mouseVisible").toBool();
@@ -144,9 +145,7 @@ void Button::mouseReleaseEvent(QMouseEvent *) {
} else if (m_buttonType == Type::colorPicker) {
}
Q_EMIT typeEmited(m_buttonType);
}
void Button::animatedShow() {
@@ -157,13 +156,14 @@ void Button::animatedShow() {
Button::Type Button::getButtonType() const {
return m_buttonType;
}
// getButtonBaseSize returns the base size of the buttons
size_t Button::getButtonBaseSize() {
return BUTTON_SIZE;
}
// getTypeByName receives a name and return the corresponding button type.
// returns Button::Type::last when the corresponding button is not found.
Button::Type Button::getTypeByName(QString s) {
Button::Type res = Button::Type::line;
Button::Type res = Type::last;
for (auto it = typeName.begin(); it != typeName.end(); ++it )
if (it->second == s)
res = it->first;

View File

@@ -49,7 +49,6 @@ public:
last
};
explicit Button(Type, QWidget *parent = 0);
static QIcon getIcon(const Type);
@@ -68,6 +67,11 @@ protected:
virtual void leaveEvent(QEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
signals:
void hovered();
void mouseExited();
void typeEmited(Type);
private:
Button(QWidget *parent = 0);
Type m_buttonType;
@@ -77,13 +81,6 @@ private:
typedef std::map<Button::Type, const QString> typeData;
static typeData typeTooltip;
static typeData typeName;
signals:
void hovered();
void mouseExited();
void typeEmited(Type);
public slots:
};
#endif // BUTTON_H

View File

@@ -52,7 +52,10 @@ bool ButtonHandler::isVisible() const {
size_t ButtonHandler::size() const {
return m_vectorButtons.size();
}
// updatePosition updates the position of the buttons arround 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,
const QRect &limits) {
const QVector<Button*>::size_type vecLength = m_vectorButtons.size();
@@ -239,6 +242,9 @@ void ButtonHandler::updatePosition(const QRect &selection,
}
}
// getHPoints is an auxiliar method for the button position computation.
// starts from a known center and keeps adding elements horizontally
// and returns the computed positions.
QVector<QPoint> ButtonHandler::getHPoints(
const QPoint &center, const int elements) const {
@@ -261,6 +267,9 @@ QVector<QPoint> ButtonHandler::getHPoints(
return res;
}
// getHPoints is an auxiliar method for the button position computation.
// starts from a known center and keeps adding elements vertically
// and returns the computed positions.
QVector<QPoint> ButtonHandler::getVPoints(
const QPoint &center, const int elements) const {
@@ -282,7 +291,7 @@ QVector<QPoint> ButtonHandler::getVPoints(
}
return res;
}
// setButtons redefines the buttons of the button handler
void ButtonHandler::setButtons(QVector<Button *> v) {
for (Button *b: m_vectorButtons) delete(b);
m_vectorButtons = v;

View File

@@ -38,6 +38,7 @@ public:
void updatePosition(const QRect &selection, const QRect &limits);
void setButtons(QVector<Button*>);
private:
QVector<QPoint> getHPoints(const QPoint &center, const int elements) const;
QVector<QPoint> getVPoints(const QPoint &center, const int elements) const;

View File

@@ -49,7 +49,7 @@ QColor CaptureModification::getColor() const {
QVector<QPoint> CaptureModification::getPoints() const {
return m_coords;
}
// addPoint adds a point to the vector of points
void CaptureModification::addPoint(const QPoint p) {
if (m_type == Button::Type::circle || m_type == Button::Type::rectangle
|| m_type == Button::Type::arrow || m_type == Button::Type::line ||

View File

@@ -31,6 +31,7 @@ public:
QColor getColor() const;
QVector<QPoint> getPoints() const;
void addPoint(const QPoint);
private:
QVector<QPoint> m_coords;
QColor m_color;

View File

@@ -42,16 +42,19 @@
// are of selection with its respective buttons.
namespace {
// size of the handlers at the corners of the selection
const int HANDLE_SIZE = 9;
}
// http://doc.qt.io/qt-5/qwidget.html#setMask
CaptureWidget::CaptureWidget(QWidget *parent) :
QWidget(parent), m_mouseOverHandle(0), m_newSelection(false),
m_grabbing(false), m_onButton(false), m_state(Button::Type::move) {
setAttribute(Qt::WA_DeleteOnClose);
QWidget(parent), m_mouseOverHandle(0), m_mouseIsClicked(false),
m_newSelection(false), m_grabbing(false), m_onButton(false),
m_state(Button::Type::move) {
setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers
QRect baseRect(0, 0, HANDLE_SIZE, HANDLE_SIZE);
m_TLHandle = baseRect; m_TRHandle = baseRect;
m_BLHandle = baseRect; m_BRHandle = baseRect;
@@ -60,7 +63,7 @@ CaptureWidget::CaptureWidget(QWidget *parent) :
m_Handles << &m_TLHandle << &m_TRHandle << &m_BLHandle << &m_BRHandle
<< &m_LHandle << &m_THandle << &m_RHandle << &m_BHandle;
// set base config of the widget
move(0,0);
setWindowFlags( Qt::WindowStaysOnTopHint
| Qt::X11BypassWindowManagerHint
@@ -69,15 +72,13 @@ CaptureWidget::CaptureWidget(QWidget *parent) :
setMouseTracking(true);
setCursor(Qt::CrossCursor);
initShortcuts();
// create buttons
m_buttonHandler = new ButtonHandler();
redefineButtons();
m_buttonHandler->hide();
// init screenshot
createCapture();
resize(m_screenshot.size());
m_mouseIsClicked = false;
m_buttonHandler->hide();
show();
}
@@ -85,6 +86,8 @@ CaptureWidget::~CaptureWidget() {
delete(m_buttonHandler);
}
// redefineButtons retrieves the buttons configured to be shown with the
// selection in the capture
void CaptureWidget::redefineButtons() {
QSettings settings;
auto buttonsInt = settings.value("buttons").value<QList<int> >();
@@ -270,7 +273,6 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
m_buttonHandler->updatePosition(m_selection, rect());
m_buttonHandler->show();
}
m_mouseIsClicked = false;
m_newSelection = false;
@@ -369,8 +371,7 @@ void CaptureWidget::downResize() {
update();
}
}
// http://stackoverflow.com/questions/10250332/qt-how-to-open-a-link-in-a-default-user-browser#10250386
// http://stackoverflow.com/questions/40292484/how-to-pass-several-parameters-when-uploading-image-to-imgur
void CaptureWidget::setState(Button::Type t) {
if(t == Button::Type::selectionIndicator ||
t == Button::Type::mouseVisibility ||

View File

@@ -19,8 +19,8 @@
#define CONFIGURATION_H
#include <QWidget>
class QListWidgetItem;
class QListWidgetItem;
class QListWidget;
class ConfigWindow : public QWidget {
@@ -28,8 +28,6 @@ class ConfigWindow : public QWidget {
public:
explicit ConfigWindow(QWidget *parent = 0);
signals:
private slots:
void updateActiveButtons(QListWidgetItem *);

View File

@@ -27,10 +27,6 @@ class InfoWindow : public QWidget {
public:
explicit InfoWindow(QWidget *parent = 0);
signals:
public slots:
private:
void initInfoTable();
QVBoxLayout *layout;

View File

@@ -31,8 +31,6 @@ public:
signals:
void activated();
public slots:
private:
void setShortcut();
};