kwave  18.07.70
Kwave::SignalView::PositionWidget Class Reference
Inheritance diagram for Kwave::SignalView::PositionWidget:
Inheritance graph
Collaboration diagram for Kwave::SignalView::PositionWidget:
Collaboration graph

Public Member Functions

 PositionWidget (QWidget *parent)
 
virtual ~PositionWidget () Q_DECL_OVERRIDE
 
virtual void setText (const QString &text, Qt::Alignment alignment)
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *) Q_DECL_OVERRIDE
 
virtual void updateMask ()
 

Private Attributes

QLabel * m_label
 
Qt::Alignment m_alignment
 
int m_radius
 
int m_arrow_length
 
Qt::Alignment m_last_alignment
 
QSize m_last_size
 
QPolygon m_polygon
 

Detailed Description

Definition at line 355 of file SignalView.h.

Constructor & Destructor Documentation

◆ PositionWidget()

Kwave::SignalView::PositionWidget::PositionWidget ( QWidget *  parent)
explicit

Constructor

Definition at line 686 of file SignalView.cpp.

References m_label.

687  :QWidget(parent), m_label(Q_NULLPTR), m_alignment(Q_NULLPTR),
688  m_radius(10), m_arrow_length(30), m_last_alignment(Qt::AlignHCenter),
689  m_last_size(QSize(0,0)), m_polygon()
690 {
691  hide();
692 
693  m_label = new QLabel(this);
694  Q_ASSERT(m_label);
695  if (!m_label) return;
696 
697  m_label->setFrameStyle(QFrame::Panel | QFrame::Plain);
698  m_label->setPalette(QToolTip::palette()); // use same colors as a QToolTip
699  m_label->setFocusPolicy(Qt::NoFocus);
700  m_label->setMouseTracking(true);
701  m_label->setLineWidth(0);
702 
703  setPalette(QToolTip::palette()); // use same colors as a QToolTip
704  setMouseTracking(false);
705  setFocusPolicy(Qt::NoFocus);
706  setAttribute(Qt::WA_TransparentForMouseEvents);
707 }

◆ ~PositionWidget()

Kwave::SignalView::PositionWidget::~PositionWidget ( )
virtual

Destructor

Definition at line 710 of file SignalView.cpp.

References m_label.

711 {
712  if (m_label) delete m_label;
713  m_label = Q_NULLPTR;
714 }

Member Function Documentation

◆ paintEvent()

void Kwave::SignalView::PositionWidget::paintEvent ( QPaintEvent *  )
protectedvirtual

paint event: draws the text and the arrow

Definition at line 815 of file SignalView.cpp.

References background, and m_polygon.

816 {
817  QPainter p(this);
818  p.setBrush(palette().background().color());
819  p.drawPolygon(m_polygon);
820 }
static const char * background[]

◆ setText()

void Kwave::SignalView::PositionWidget::setText ( const QString &  text,
Qt::Alignment  alignment 
)
virtual

set a new label text and alignment

Parameters
textthe text of the label, can be multiline and rtf/html
alignmentthe alignment of the label and the widget, can be Qt::AlignLeft, Qt::AlignRight or Qt::AlignHCenter

Definition at line 717 of file SignalView.cpp.

References m_alignment, m_arrow_length, m_label, m_radius, and updateMask().

Referenced by Kwave::SignalView::showPosition().

719 {
720  if (!m_label) return;
721 
722  m_alignment = alignment;
723 
724  m_label->setText(text);
725  m_label->setAlignment(m_alignment);
726  m_label->resize(m_label->sizeHint());
727 
728  switch (m_alignment) {
729  case Qt::AlignLeft:
730  resize(m_arrow_length + m_radius + m_label->width() + m_radius,
731  m_radius + m_label->height() + m_radius);
733  break;
734  case Qt::AlignRight:
735  resize(m_radius + m_label->width() + m_radius + m_arrow_length,
736  m_radius + m_label->height() + m_radius);
737  m_label->move(m_radius, m_radius);
738  break;
739  case Qt::AlignHCenter:
740  resize(m_radius + m_label->width() + m_radius,
741  m_arrow_length + m_radius + m_label->height() + m_radius);
742  m_label->move(m_radius, m_arrow_length + m_radius);
743  break;
744  default:
745  ;
746  }
747 
748  updateMask();
749 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateMask()

void Kwave::SignalView::PositionWidget::updateMask ( )
protectedvirtual

re-creates the mask and the polygon when size/alignment has changed

Definition at line 752 of file SignalView.cpp.

References m_alignment, m_arrow_length, m_last_alignment, m_last_size, and m_polygon.

Referenced by setText().

753 {
754  // bail out if nothing has changed
755  if ((size() == m_last_size) && (m_alignment == m_last_alignment))
756  return;
757 
758  QPainter p;
759  QBitmap bmp(size());
760  bmp.fill(Qt::color0);
761  p.begin(&bmp);
762 
763  QBrush brush(Qt::color1);
764  p.setBrush(brush);
765  p.setPen(Qt::color1);
766 
767  const int h = height();
768  const int w = width();
769 
770  // re-create the polygon, depending on alignment
771  switch (m_alignment) {
772  case Qt::AlignLeft:
773  m_polygon.setPoints(8,
774  m_arrow_length, 0,
775  w - 1, 0,
776  w - 1, h - 1,
777  m_arrow_length, h - 1,
778  m_arrow_length, (2 * h) / 3,
779  0, h / 2,
780  m_arrow_length, h / 3,
781  m_arrow_length, 0
782  );
783  break;
784  case Qt::AlignRight:
785  m_polygon.setPoints(8,
786  0, 0,
787  w - 1 - m_arrow_length, 0,
788  w - 1 - m_arrow_length, h / 3,
789  w - 1, h/2,
790  w - 1 - m_arrow_length, (2 * h) / 3,
791  w - 1 - m_arrow_length, h - 1,
792  0, h - 1,
793  0, 0
794  );
795  break;
796  case Qt::AlignHCenter:
797  break;
798  default:
799  ;
800  }
801 
802  p.drawPolygon(m_polygon);
803  p.end();
804 
805  // activate the new widget mask
806  clearMask();
807  setMask(bmp);
808 
809  // remember size/alignment for detecting changes
811  m_last_size = size();
812 }
Here is the caller graph for this function:

Member Data Documentation

◆ m_alignment

Qt::Alignment Kwave::SignalView::PositionWidget::m_alignment
private

alignment of the label / text

Definition at line 389 of file SignalView.h.

Referenced by setText(), and updateMask().

◆ m_arrow_length

int Kwave::SignalView::PositionWidget::m_arrow_length
private

the length of the arrows [pixel]

Definition at line 395 of file SignalView.h.

Referenced by setText(), and updateMask().

◆ m_label

QLabel* Kwave::SignalView::PositionWidget::m_label
private

the label that contains the text

Definition at line 386 of file SignalView.h.

Referenced by PositionWidget(), setText(), and ~PositionWidget().

◆ m_last_alignment

Qt::Alignment Kwave::SignalView::PositionWidget::m_last_alignment
private

for detecting changes: previous width

Definition at line 398 of file SignalView.h.

Referenced by updateMask().

◆ m_last_size

QSize Kwave::SignalView::PositionWidget::m_last_size
private

for detecting changes: previous size

Definition at line 401 of file SignalView.h.

Referenced by updateMask().

◆ m_polygon

QPolygon Kwave::SignalView::PositionWidget::m_polygon
private

polygon used as widget outline

Definition at line 404 of file SignalView.h.

Referenced by paintEvent(), and updateMask().

◆ m_radius

int Kwave::SignalView::PositionWidget::m_radius
private

the radius of the corners [pixel]

Definition at line 392 of file SignalView.h.

Referenced by setText().


The documentation for this class was generated from the following files: