window resizing

This commit is contained in:
ingvar1995 2016-05-02 18:27:46 +03:00
parent 2c215ef0c6
commit 7a02ae3ef4
3 changed files with 50 additions and 28 deletions

View File

@ -136,10 +136,10 @@ class StatusCircle(QtGui.QWidget):
class FileTransferItem(QtGui.QListWidget):
def __init__(self, file_name, size, time, user, friend_number, file_number, state, parent=None):
def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):
QtGui.QListWidget.__init__(self, parent)
self.resize(QtCore.QSize(620, 50))
self.resize(QtCore.QSize(width, 50))
if state != FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']:
self.setStyleSheet('QWidget { background-color: green; }')
else:
@ -237,23 +237,24 @@ class FileTransferItem(QtGui.QListWidget):
class InlineImageItem(QtGui.QWidget):
def __init__(self, data, parent=None):
def __init__(self, data, width, parent=None):
QtGui.QWidget.__init__(self, parent)
self.resize(QtCore.QSize(620, 500))
self.resize(QtCore.QSize(width, 500))
self._image_label = QtGui.QLabel(self)
self._image_label.raise_()
self._image_label.setAutoFillBackground(True)
self._image_label.setScaledContents(False)
self.pixmap = QtGui.QPixmap()
self.pixmap.loadFromData(QtCore.QByteArray(data), "PNG")
if self.pixmap.width() <= 600:
max_size = width - 50
if self.pixmap.width() <= max_size:
self._image_label.setPixmap(self.pixmap)
self.resize(QtCore.QSize(600, self.pixmap.height()))
self.resize(QtCore.QSize(max_size, self.pixmap.height()))
else:
pixmap = self.pixmap.scaled(600, 600, QtCore.Qt.KeepAspectRatio)
pixmap = self.pixmap.scaled(max_size, max_size, QtCore.Qt.KeepAspectRatio)
self._image_label.setPixmap(pixmap)
self.resize(QtCore.QSize(600, pixmap.height()))
self.resize(QtCore.QSize(max_size, pixmap.height()))

View File

@ -109,36 +109,37 @@ class MainWindow(QtGui.QMainWindow):
self.actionAbout_program.setText(QtGui.QApplication.translate("MainWindow", "About program", None, QtGui.QApplication.UnicodeUTF8))
self.actionSettings.setText(QtGui.QApplication.translate("MainWindow", "Settings", None, QtGui.QApplication.UnicodeUTF8))
self.audioSettings.setText(QtGui.QApplication.translate("MainWindow", "Audio", None, QtGui.QApplication.UnicodeUTF8))
self.contact_name.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Find contact", None, QtGui.QApplication.UnicodeUTF8))
def setup_right_bottom(self, Form):
Form.setObjectName("right_bottom")
Form.resize(650, 100)
Form.resize(650, 80)
self.messageEdit = MessageArea(Form, self)
self.messageEdit.setGeometry(QtCore.QRect(0, 10, 450, 110))
self.messageEdit.setGeometry(QtCore.QRect(0, 5, 450, 70))
self.messageEdit.setObjectName("messageEdit")
self.screenshotButton = QtGui.QPushButton(Form)
self.screenshotButton.setGeometry(QtCore.QRect(460, 10, 90, 55))
self.screenshotButton.setGeometry(QtCore.QRect(455, 5, 55, 70))
self.screenshotButton.setObjectName("screenshotButton")
self.fileTransferButton = QtGui.QPushButton(Form)
self.fileTransferButton.setGeometry(QtCore.QRect(460, 65, 90, 55))
self.fileTransferButton.setGeometry(QtCore.QRect(510, 5, 55, 70))
self.fileTransferButton.setObjectName("fileTransferButton")
self.sendMessageButton = QtGui.QPushButton(Form)
self.sendMessageButton.setGeometry(QtCore.QRect(550, 10, 70, 110))
self.sendMessageButton.setGeometry(QtCore.QRect(565, 5, 55, 70))
self.sendMessageButton.setObjectName("sendMessageButton")
self.sendMessageButton.clicked.connect(self.send_message)
pixmap = QtGui.QPixmap(curr_directory() + '/images/send.png')
icon = QtGui.QIcon(pixmap)
self.sendMessageButton.setIcon(icon)
self.sendMessageButton.setIconSize(QtCore.QSize(50, 100))
self.sendMessageButton.setIconSize(QtCore.QSize(45, 60))
pixmap = QtGui.QPixmap(curr_directory() + '/images/file.png')
icon = QtGui.QIcon(pixmap)
self.fileTransferButton.setIcon(icon)
self.fileTransferButton.setIconSize(QtCore.QSize(90, 40))
self.fileTransferButton.setIconSize(QtCore.QSize(55, 70))
pixmap = QtGui.QPixmap(curr_directory() + '/images/screenshot.png')
icon = QtGui.QIcon(pixmap)
self.screenshotButton.setIcon(icon)
self.screenshotButton.setIconSize(QtCore.QSize(90, 40))
self.screenshotButton.setIconSize(QtCore.QSize(40, 60))
self.fileTransferButton.clicked.connect(self.send_file)
self.screenshotButton.clicked.connect(self.send_screenshot)
@ -146,13 +147,13 @@ class MainWindow(QtGui.QMainWindow):
def setup_left_bottom(self, Form):
Form.setObjectName("left_bottom")
Form.resize(500, 60)
Form.resize(270, 80)
self.online_contacts = QtGui.QCheckBox(Form)
self.online_contacts.setGeometry(QtCore.QRect(0, 0, 250, 20))
self.online_contacts.setGeometry(QtCore.QRect(0, 10, 250, 20))
self.online_contacts.setObjectName("online_contacts")
self.online_contacts.clicked.connect(self.filtering)
self.contact_name = QtGui.QLineEdit(Form)
self.contact_name.setGeometry(QtCore.QRect(0, 27, 270, 30))
self.contact_name.setGeometry(QtCore.QRect(0, 45, 270, 30))
self.contact_name.setObjectName("contact_name")
self.contact_name.textChanged.connect(self.filtering)
QtCore.QMetaObject.connectSlotsByName(Form)
@ -240,10 +241,11 @@ class MainWindow(QtGui.QMainWindow):
def setup_right_center(self, widget):
self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 620, 250)
self.messages.setGeometry(0, 0, 620, 310)
self.messages.setObjectName("messages")
self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.messages.setFocusPolicy(QtCore.Qt.NoFocus)
def load(pos):
if not pos:
@ -254,14 +256,14 @@ class MainWindow(QtGui.QMainWindow):
def initUI(self, tox):
self.setMinimumSize(920, 500)
self.setMaximumSize(920, 500)
#self.setMaximumSize(920, 500)
self.setGeometry(400, 400, 920, 500)
self.setWindowTitle('Toxygen')
main = QtGui.QWidget()
grid = QtGui.QGridLayout()
search = QtGui.QWidget()
self.setup_left_bottom(search)
grid.addWidget(search, 3, 0)
grid.addWidget(search, 2, 0)
name = QtGui.QWidget()
self.setup_left_top(name)
grid.addWidget(name, 0, 0)
@ -273,14 +275,17 @@ class MainWindow(QtGui.QMainWindow):
grid.addWidget(info, 0, 1)
message_buttons = QtGui.QWidget()
self.setup_right_bottom(message_buttons)
grid.addWidget(message_buttons, 2, 1, 2, 1)
grid.addWidget(message_buttons, 2, 1)
main_list = QtGui.QWidget()
self.setup_left_center(main_list)
grid.addWidget(main_list, 1, 0, 2, 1)
grid.addWidget(main_list, 1, 0)
grid.setColumnMinimumWidth(1, 500)
grid.setColumnMinimumWidth(0, 270)
grid.setRowMinimumHeight(1, 250)
grid.setRowMinimumHeight(3, 50)
grid.setRowMinimumHeight(2, 75)
grid.setColumnStretch(1, 1)
grid.setRowStretch(1, 1)
#grid.setRowStretch(2, 1)
main.setLayout(grid)
self.setCentralWidget(main)
self.setup_menu(self)
@ -294,6 +299,17 @@ class MainWindow(QtGui.QMainWindow):
self.profile.close()
QtGui.QApplication.closeAllWindows()
def resizeEvent(self, *args, **kwargs):
self.messages.setGeometry(0, 0, self.width() - 280, self.height() - 205)
self.friends_list.setGeometry(0, 0, 270, self.height() - 205)
self.callButton.setGeometry(QtCore.QRect(self.width() - 370, 30, 50, 50))
self.typing.setGeometry(QtCore.QRect(self.width() - 420, 40, 50, 30))
self.messageEdit.setGeometry(QtCore.QRect(0, 5, self.width() - 470, 70))
self.screenshotButton.setGeometry(QtCore.QRect(self.width() - 465, 5, 55, 70))
self.fileTransferButton.setGeometry(QtCore.QRect(self.width() - 410, 5, 55, 70))
self.sendMessageButton.setGeometry(QtCore.QRect(self.width() - 355, 5, 55, 70))
self.profile.update()
# -----------------------------------------------------------------------------------------------------------------
# Functions which called when user click in menu
# -----------------------------------------------------------------------------------------------------------------

View File

@ -456,6 +456,10 @@ class Profile(Contact, Singleton):
def is_active_online(self):
return self._active_friend + 1 and self._friends[self._active_friend].status is not None
def update(self):
if self._active_friend + 1:
self.set_active(self._active_friend)
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
@ -622,9 +626,10 @@ class Profile(Contact, Singleton):
def create_file_transfer_item(self, tm, append=True):
data = list(tm.get_data())
data[3] = self.get_friend_by_number(data[4]).name if data[3] else self._name
data.append(self._messages.width())
item = FileTransferItem(*data)
elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(600, 50))
elem.setSizeHint(QtCore.QSize(self._messages.width(), 50))
if append:
self._messages.addItem(elem)
else:
@ -633,9 +638,9 @@ class Profile(Contact, Singleton):
return item
def create_inline_item(self, data, append=True):
item = InlineImageItem(data)
item = InlineImageItem(data, self._messages.width())
elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(600, item.height()))
elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append:
self._messages.addItem(elem)
else: