![]() |
Mixxx
|
00001 /*************************************************************************** 00002 wvisualsimple.cpp - description 00003 ------------------- 00004 begin : Thu Oct 9 2003 00005 copyright : (C) 2002 by Tue & Ken Haste Andersen 00006 email : haste@diku.dk 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "wvisualsimple.h" 00019 #include "wskincolor.h" 00020 #include <qpainter.h> 00021 #include <qpixmap.h> 00022 #include <QDragEnterEvent> 00023 #include <QDropEvent> 00024 #include <QMouseEvent> 00025 #include <QPaintEvent> 00026 #include <QUrl> 00027 00028 #include "waveform/waveformrenderer.h" 00029 00030 WVisualSimple::WVisualSimple(const char* group, QWidget * parent, WaveformRenderer* pWaveformRenderer) 00031 : WWidget(parent), 00032 m_group(group), 00033 m_iValue(64), 00034 m_pWaveformRenderer(pWaveformRenderer) 00035 00036 { 00037 setAcceptDrops(true); 00038 } 00039 00040 WVisualSimple::~WVisualSimple() 00041 { 00042 } 00043 00044 void WVisualSimple::dragEnterEvent(QDragEnterEvent * event) 00045 { 00046 if (event->mimeData()->hasUrls()) 00047 event->acceptProposedAction(); 00048 } 00049 00050 void WVisualSimple::dropEvent(QDropEvent * event) 00051 { 00052 if (event->mimeData()->hasUrls()) { 00053 QList<QUrl> urls(event->mimeData()->urls()); 00054 QUrl url = urls.first(); 00055 QString name = url.toLocalFile(); 00056 00057 event->accept(); 00058 emit(trackDropped(name, m_group)); 00059 } else 00060 event->ignore(); 00061 } 00062 00063 void WVisualSimple::setup(QDomNode node) 00064 { 00065 int w = width(), h = height(); 00066 00067 m_pWaveformRenderer->resize(w,h); 00068 m_pWaveformRenderer->setup(node); 00069 00070 // Set constants for line drawing 00071 m_qMarkerPos1.setX(w/2); 00072 m_qMarkerPos1.setY(0); 00073 m_qMarkerPos2.setX(w/2); 00074 m_qMarkerPos2.setY(h); 00075 m_qMousePos.setX(w/2); 00076 m_qMousePos.setY(h/2); 00077 00078 // Background color 00079 QColor c(255,255,255); 00080 if (!selectNode(node, "BgColor").isNull()) 00081 { 00082 c.setNamedColor(selectNodeQString(node, "BgColor")); 00083 } 00084 00085 //the simple view seems to look fine even if we never set a background colour at all 00086 //but since the code used to do it, we'll continue to do it --kousu 2009/03 00087 QPalette palette = this->palette(); 00088 //setBackgroundColor(WSkinColor::getCorrectColor(c)); 00089 palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(c)); 00090 setPalette(palette); 00091 00092 colorSignal.setNamedColor(selectNodeQString(node, "SignalColor")); 00093 colorSignal = WSkinColor::getCorrectColor(colorSignal); 00094 colorMarker.setNamedColor(selectNodeQString(node, "MarkerColor")); 00095 colorMarker = WSkinColor::getCorrectColor(colorMarker); 00096 } 00097 00098 void WVisualSimple::refresh() { 00099 // Do nothing since its the simple waveform. 00100 } 00101 00102 void WVisualSimple::mouseMoveEvent(QMouseEvent * e) 00103 { 00104 // Only process mouse move if it was initiated by a left click 00105 if (m_iStartPosX!=-1) 00106 { 00107 double v = 64.+(double)(e->x()-m_iStartPosX)/10.; 00108 if (v<0.) 00109 v = 0.; 00110 else if (v>127.) 00111 v = 127.; 00112 emit(valueChangedLeftDown(v)); 00113 m_iValue = (int)v; 00114 } 00115 update(); 00116 } 00117 00118 void WVisualSimple::mousePressEvent(QMouseEvent * e) 00119 { 00120 m_iStartPosX = -1; 00121 if (e->button()==Qt::LeftButton) 00122 { 00123 // Store current x position of mouse pointer 00124 m_iStartPosX = e->x(); 00125 emit(valueChangedLeftDown(64.)); 00126 } 00127 } 00128 00129 void WVisualSimple::mouseReleaseEvent(QMouseEvent *) 00130 { 00131 m_iValue = 64; 00132 emit(valueChangedLeftDown((double)m_iValue)); 00133 update(); 00134 } 00135 00136 void WVisualSimple::paintEvent(QPaintEvent *) 00137 { 00138 QPainter paint(this); 00139 00140 // Draw vertical red bar in center 00141 paint.setPen(colorMarker); 00142 paint.drawLine(m_qMarkerPos1, m_qMarkerPos2); 00143 00144 // Draw lines indicating position 00145 if (m_iValue!=64) 00146 { 00147 paint.setPen(colorSignal); 00148 QPoint p1 = m_qMousePos+QPoint((m_iValue-64)*2,0); 00149 QPoint p2 = m_qMousePos+QPoint((m_iValue-64)*2,0); 00150 paint.drawLine(m_qMarkerPos1, p1); 00151 paint.drawLine(m_qMarkerPos2, p2); 00152 } 00153 } 00154 00155 00156