1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_DropBox.h"
24 #include "../tmp/UIC_DropBox.h"
27 #include "Model_Settings.h"
32 #include <QDesktopWidget>
37 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = (WIDGET)->font(); _font.setBold(BOLD); (WIDGET)->setFont(_font); }
39 ////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////
43 DropBox::DropBox(QWidget
*parent
, QAbstractItemModel
*model
, SettingsModel
*settings
)
45 QDialog(parent
, Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
),
52 //Init the dialog, from the .ui file
56 m_counterLabel
= new QLabel(this);
57 m_counterLabel
->setParent(ui
->dropBoxLabel
);
58 m_counterLabel
->setText("0");
59 m_counterLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignTop
);
60 SET_FONT_BOLD(m_counterLabel
, true);
62 m_windowReferencePoint
= new QPoint
;
63 m_mouseReferencePoint
= new QPoint
;
69 setWindowOpacity(0.8);
72 QEvent
languageChangeEvent(QEvent::LanguageChange
);
73 changeEvent(&languageChangeEvent
);
76 ////////////////////////////////////////////////////////////
78 ////////////////////////////////////////////////////////////
80 DropBox::~DropBox(void)
82 LAMEXP_DELETE(m_counterLabel
);
83 LAMEXP_DELETE(m_windowReferencePoint
);
84 LAMEXP_DELETE(m_mouseReferencePoint
);
88 ////////////////////////////////////////////////////////////
90 ////////////////////////////////////////////////////////////
92 void DropBox::modelChanged(void)
96 m_counterLabel
->setText(QString::number(m_model
->rowCount()));
100 ////////////////////////////////////////////////////////////
102 ////////////////////////////////////////////////////////////
105 * Re-translate the UI
107 void DropBox::changeEvent(QEvent
*e
)
109 if(e
->type() == QEvent::LanguageChange
)
111 ui
->retranslateUi(this);
112 ui
->dropBoxLabel
->setToolTip(QString("<b>%1</b><br><nobr>%2</nobr><br><nobr>%3</nobr>").arg(tr("LameXP DropBox"), tr("You can add files to LameXP via Drag&Drop here!"), tr("(Right-click to close the DropBox)")));
116 void DropBox::showEvent(QShowEvent
*event
)
118 QRect screenGeometry
= QApplication::desktop()->availableGeometry();
120 resize(ui
->dropBoxLabel
->pixmap()->size());
121 setMaximumSize(ui
->dropBoxLabel
->pixmap()->size());
123 m_counterLabel
->setGeometry(0, ui
->dropBoxLabel
->height() - 30, ui
->dropBoxLabel
->width(), 25);
128 int max_x
= screenGeometry
.width() - frameGeometry().width() + screenGeometry
.left();
129 int max_y
= screenGeometry
.height() - frameGeometry().height() + screenGeometry
.top();
131 QTimer::singleShot(333, this, SLOT(showToolTip()));
136 QApplication::restoreOverrideCursor();
141 void DropBox::keyPressEvent(QKeyEvent
*event
)
146 void DropBox::keyReleaseEvent(QKeyEvent
*event
)
151 void DropBox::closeEvent(QCloseEvent
*event
)
153 if(!m_canClose
) event
->ignore();
156 void DropBox::mousePressEvent(QMouseEvent
*event
)
164 if(event
->button() == Qt::RightButton
)
167 if(m_settings
) m_settings
->dropBoxWidgetEnabled(false);
171 QApplication::setOverrideCursor(Qt::SizeAllCursor
);
172 *m_windowReferencePoint
= this->pos();
173 *m_mouseReferencePoint
= event
->globalPos();
177 void DropBox::mouseReleaseEvent(QMouseEvent
*event
)
179 if(m_moving
&& event
->button() != Qt::RightButton
)
181 QApplication::restoreOverrideCursor();
186 void DropBox::mouseMoveEvent(QMouseEvent
*event
)
193 static const int magnetic
= 22;
194 QRect screenGeometry
= QApplication::desktop()->availableGeometry();
196 const int delta_x
= m_mouseReferencePoint
->x() - event
->globalX();
197 const int delta_y
= m_mouseReferencePoint
->y() - event
->globalY();
198 const int max_x
= screenGeometry
.width() - frameGeometry().width() + screenGeometry
.left();
199 const int max_y
= screenGeometry
.height() - frameGeometry().height() + screenGeometry
.top();
201 int new_x
= qMin(max_x
, qMax(screenGeometry
.left(), m_windowReferencePoint
->x() - delta_x
));
202 int new_y
= qMin(max_y
, qMax(screenGeometry
.top(), m_windowReferencePoint
->y() - delta_y
));
208 else if(max_x
- new_x
< magnetic
)
217 else if(max_y
- new_y
< magnetic
)
225 void DropBox::showToolTip(void)
227 QToolTip::showText(ui
->dropBoxLabel
->mapToGlobal(ui
->dropBoxLabel
->pos()), ui
->dropBoxLabel
->toolTip());
230 bool DropBox::event(QEvent
*event
)
232 switch(event
->type())
235 case QEvent::WindowDeactivate
:
238 QApplication::restoreOverrideCursor();
244 return QDialog::event(event
);