PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/autoroute/zoomcontrols.cpp

https://gitlab.com/billhibadb/fritzing-app
C++ | 104 lines | 59 code | 16 blank | 29 comment | 10 complexity | f35ca9f6a14c1a377abfbef9c4950ce0 MD5 | raw file
  1. /*******************************************************************
  2. Part of the Fritzing project - http://fritzing.org
  3. Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
  4. Fritzing is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Fritzing is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
  14. ********************************************************************
  15. $Revision: 6904 $:
  16. $Author: irascibl@gmail.com $:
  17. $Date: 2013-02-26 16:26:03 +0100 (Di, 26. Feb 2013) $
  18. ********************************************************************/
  19. #include "zoomcontrols.h"
  20. #include "../debugdialog.h"
  21. #include "../utils/zoomslider.h"
  22. ZoomButton::ZoomButton(QBoxLayout::Direction dir, ZoomButton::ZoomType type, ZoomableGraphicsView* view, QWidget *parent) : QLabel(parent)
  23. {
  24. QString imgPath = ":/resources/images/icons/partsEditorZoom%1%2Button.png";
  25. QString typeStr = type==ZoomButton::ZoomIn? "In": "Out";
  26. QString dirStr;
  27. if(dir == QBoxLayout::LeftToRight || dir == QBoxLayout::RightToLeft) {
  28. dirStr = "Hor";
  29. } else if(dir == QBoxLayout::TopToBottom || dir == QBoxLayout::BottomToTop) {
  30. dirStr = "Ver";
  31. }
  32. imgPath = imgPath.arg(typeStr).arg(dirStr);
  33. m_step = 5*ZoomSlider::ZoomStep;
  34. m_type = type;
  35. m_owner = view;
  36. connect(this, SIGNAL(clicked()), this, SLOT(zoom()) );
  37. setPixmap(QPixmap(imgPath));
  38. }
  39. void ZoomButton::zoom() {
  40. int inOrOut = m_type == ZoomButton::ZoomIn? 1: -1;
  41. m_owner->relativeZoom(inOrOut*m_step, false);
  42. m_owner->ensureFixedToBottomRightItems();
  43. }
  44. void ZoomButton::mousePressEvent(QMouseEvent *event) {
  45. //QLabel::mousePressEvent(event);
  46. Q_UNUSED(event);
  47. emit clicked();
  48. }
  49. void ZoomButton::enterEvent(QEvent *event) {
  50. QLabel::enterEvent(event);
  51. }
  52. void ZoomButton::leaveEvent(QEvent *event) {
  53. QLabel::leaveEvent(event);
  54. }
  55. ///////////////////////////////////////////////////////////
  56. ZoomControlsPrivate::ZoomControlsPrivate(ZoomableGraphicsView* view, QBoxLayout::Direction dir, QWidget *parent) : QFrame(parent)
  57. {
  58. //setObjectName("zoomControls");
  59. m_zoomInButton = new ZoomButton(dir, ZoomButton::ZoomIn, view, this);
  60. m_zoomOutButton = new ZoomButton(dir, ZoomButton::ZoomOut, view, this);
  61. m_boxLayout = new QBoxLayout(dir,this);
  62. m_boxLayout->addWidget(m_zoomInButton);
  63. m_boxLayout->addWidget(m_zoomOutButton);
  64. m_boxLayout->setMargin(2);
  65. m_boxLayout->setSpacing(2);
  66. setStyleSheet("background-color: transparent;");
  67. }
  68. ///////////////////////////////////////////////////////////
  69. ZoomControls::ZoomControls(ZoomableGraphicsView *view, QWidget *parent)
  70. : ZoomControlsPrivate(view, QBoxLayout::RightToLeft, parent)
  71. {
  72. m_zoomLabel = new QLabel(this);
  73. m_zoomLabel->setFixedWidth(35);
  74. connect(view, SIGNAL(zoomChanged(double)),this,SLOT(updateLabel(double)));
  75. m_boxLayout->insertWidget(1,m_zoomLabel); // in the middle
  76. m_boxLayout->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Minimum)); // at the beginning
  77. updateLabel(view->currentZoom());
  78. }
  79. void ZoomControls::updateLabel(double zoom) {
  80. m_zoomLabel->setText(QString("%1%").arg((int)zoom));
  81. }