1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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>
35 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET.font(); _font.setBold(BOLD); WIDGET.setFont(_font); }
37 ////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////
41 DropBox::DropBox(QWidget
*parent
, QAbstractItemModel
*model
, SettingsModel
*settings
)
43 QDialog(parent
, Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
),
50 //Init the dialog, from the .ui file
54 m_counterLabel
.setParent(dropBoxLabel
);
55 m_counterLabel
.setText("0");
56 m_counterLabel
.setAlignment(Qt::AlignHCenter
| Qt::AlignTop
);
57 SET_FONT_BOLD(m_counterLabel
, true);
63 setWindowOpacity(0.8);
66 QEvent
languageChangeEvent(QEvent::LanguageChange
);
67 changeEvent(&languageChangeEvent
);
70 ////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////
74 DropBox::~DropBox(void)
78 ////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////
82 void DropBox::modelChanged(void)
86 m_counterLabel
.setText(QString::number(m_model
->rowCount()));
90 ////////////////////////////////////////////////////////////
92 ////////////////////////////////////////////////////////////
97 void DropBox::changeEvent(QEvent
*e
)
99 if(e
->type() == QEvent::LanguageChange
)
101 Ui::DropBox::retranslateUi(this);
102 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)")));
106 void DropBox::showEvent(QShowEvent
*event
)
108 QRect screenGeometry
= QApplication::desktop()->availableGeometry();
110 resize(dropBoxLabel
->pixmap()->size());
111 setMaximumSize(dropBoxLabel
->pixmap()->size());
113 m_counterLabel
.setGeometry(0, dropBoxLabel
->height() - 30, dropBoxLabel
->width(), 25);
118 int max_x
= screenGeometry
.width() - frameGeometry().width() + screenGeometry
.left();
119 int max_y
= screenGeometry
.height() - frameGeometry().height() + screenGeometry
.top();
121 QTimer::singleShot(333, this, SLOT(showToolTip()));
126 QApplication::restoreOverrideCursor();
131 void DropBox::keyPressEvent(QKeyEvent
*event
)
136 void DropBox::keyReleaseEvent(QKeyEvent
*event
)
141 void DropBox::closeEvent(QCloseEvent
*event
)
143 if(!m_canClose
) event
->ignore();
146 void DropBox::mousePressEvent(QMouseEvent
*event
)
154 if(event
->button() == Qt::RightButton
)
157 if(m_settings
) m_settings
->dropBoxWidgetEnabled(false);
161 QApplication::setOverrideCursor(Qt::SizeAllCursor
);
163 m_windowReferencePoint
= this->pos();
164 m_mouseReferencePoint
= event
->globalPos();
167 void DropBox::mouseReleaseEvent(QMouseEvent
*event
)
169 if(m_moving
&& event
->button() != Qt::RightButton
)
171 QApplication::restoreOverrideCursor();
176 void DropBox::mouseMoveEvent(QMouseEvent
*event
)
183 static const int magnetic
= 22;
184 QRect screenGeometry
= QApplication::desktop()->availableGeometry();
186 const int delta_x
= m_mouseReferencePoint
.x() - event
->globalX();
187 const int delta_y
= m_mouseReferencePoint
.y() - event
->globalY();
188 const int max_x
= screenGeometry
.width() - frameGeometry().width() + screenGeometry
.left();
189 const int max_y
= screenGeometry
.height() - frameGeometry().height() + screenGeometry
.top();
191 int new_x
= min(max_x
, max(screenGeometry
.left(), m_windowReferencePoint
.x() - delta_x
));
192 int new_y
= min(max_y
, max(screenGeometry
.top(), m_windowReferencePoint
.y() - delta_y
));
198 else if(max_x
- new_x
< magnetic
)
207 else if(max_y
- new_y
< magnetic
)
215 void DropBox::showToolTip(void)
217 QToolTip::showText(dropBoxLabel
->mapToGlobal(dropBoxLabel
->pos()), dropBoxLabel
->toolTip());
220 bool DropBox::event(QEvent
*event
)
222 switch(event
->type())
225 case QEvent::WindowDeactivate
:
228 QApplication::restoreOverrideCursor();
234 return QDialog::event(event
);