1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2010 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"
25 #include "Model_Settings.h"
30 #include <QDesktopWidget>
36 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET.font(); _font.setBold(BOLD); WIDGET.setFont(_font); }
38 ////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////
42 DropBox::DropBox(QWidget *parent, QAbstractItemModel *model, SettingsModel *settings)
44 QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint),
51 //Init the dialog, from the .ui file
55 m_counterLabel.setParent(dropBoxLabel);
56 m_counterLabel.setText("0");
57 m_counterLabel.setAlignment(Qt::AlignHCenter | Qt::AlignTop);
58 SET_FONT_BOLD(m_counterLabel, true);
64 setWindowOpacity(0.8);
70 ////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////
74 DropBox::~DropBox(void)
78 ////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////
82 void DropBox::doRetranslate(void)
87 void DropBox::modelChanged(void)
91 m_counterLabel.setText(QString::number(m_model->rowCount()));
95 ////////////////////////////////////////////////////////////
97 ////////////////////////////////////////////////////////////
100 * Re-translate the UI
102 void DropBox::changeEvent(QEvent *e)
104 if(e->type() == QEvent::LanguageChange)
106 Ui::DropBox::retranslateUi(this);
107 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)")));
112 void DropBox::showEvent(QShowEvent *event)
114 QRect screenGeometry = QApplication::desktop()->availableGeometry();
116 resize(dropBoxLabel->pixmap()->size());
117 setMaximumSize(dropBoxLabel->pixmap()->size());
119 m_counterLabel.setGeometry(0, dropBoxLabel->height() - 30, dropBoxLabel->width(), 25);
124 int max_x = screenGeometry.width() - frameGeometry().width();
125 int max_y = screenGeometry.height() - frameGeometry().height();
127 QTimer::singleShot(333, this, SLOT(showToolTip()));
133 void DropBox::keyPressEvent(QKeyEvent *event)
138 void DropBox::keyReleaseEvent(QKeyEvent *event)
143 void DropBox::closeEvent(QCloseEvent *event)
145 if(!m_canClose) event->ignore();
148 void DropBox::mousePressEvent(QMouseEvent *event)
156 if(event->button() == Qt::RightButton)
159 if(m_settings) m_settings->dropBoxWidgetEnabled(false);
163 QApplication::setOverrideCursor(Qt::SizeAllCursor);
165 m_windowReferencePoint = this->pos();
166 m_mouseReferencePoint = event->globalPos();
169 void DropBox::mouseReleaseEvent(QMouseEvent *event)
171 if(m_moving && event->button() != Qt::RightButton)
173 QApplication::restoreOverrideCursor();
178 void DropBox::mouseMoveEvent(QMouseEvent *event)
185 static const int magnetic = 22;
186 QRect screenGeometry = QApplication::desktop()->availableGeometry();
188 int delta_x = m_mouseReferencePoint.x() - event->globalX();
189 int delta_y = m_mouseReferencePoint.y() - event->globalY();
191 int max_x = screenGeometry.width() - frameGeometry().width();
192 int max_y = screenGeometry.height() - frameGeometry().height();
194 int new_x = min(max_x, max(0, m_windowReferencePoint.x() - delta_x));
195 int new_y = min(max_y, max(0, m_windowReferencePoint.y() - delta_y));
201 else if(max_x - new_x < magnetic)
210 else if(max_y - new_y < magnetic)
218 void DropBox::showToolTip(void)
220 QToolTip::showText(dropBoxLabel->mapToGlobal(dropBoxLabel->pos()), dropBoxLabel->toolTip());