diff --git a/rare/components/tabs/shop/game_info.py b/rare/components/tabs/shop/game_info.py index 0a403f22..dcdbd261 100644 --- a/rare/components/tabs/shop/game_info.py +++ b/rare/components/tabs/shop/game_info.py @@ -2,7 +2,8 @@ import logging import webbrowser from PyQt5.QtGui import QPixmap, QFont -from PyQt5.QtWidgets import QWidget, QLabel +from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QHBoxLayout +from qtawesome import icon from rare.components.tabs.shop.shop_models import ShopGame from rare.ui.components.tabs.store.shop_game_info import Ui_shop_info @@ -124,7 +125,14 @@ class ShopGameInfo(QWidget, Ui_shop_info): else: self.req_group_box.layout().addWidget(QLabel(self.tr("Could not get requirements"))) - self.image.update_image(self.game.image_urls.front_tall, self.game.title, (240, 320)) + if self.game.image_urls.front_tall: + img = self.game.image_urls.front_tall + elif self.game.image_urls.offer_image_tall: + img = self.game.image_urls.offer_image_tall + else: + img = "" + + self.image.update_image(img, self.game.title, (240, 320)) self.image_stack.setCurrentIndex(0) try: @@ -136,6 +144,34 @@ class ShopGameInfo(QWidget, Ui_shop_info): pass self.tags.setText(", ".join(self.game.tags)) + # clear Layout + QWidget().setLayout(self.social_link_gb.layout()) + self.social_link_gb.setLayout(QHBoxLayout()) + + self.social_link_gb.layout().addStretch(1) + link_count = 0 + for name, url in self.game.links: + + if name.lower() == "homepage": + icn = icon("mdi.web", scale_factor=1.5) + else: + try: + icn = icon("mdi." + name.lower(), scale_factor=1.5) + except Exception as e: + logger.error(str(e)) + continue + + button = SocialButton(icn, url) + self.social_link_gb.layout().addWidget(button) + link_count += 1 + self.social_link_gb.layout().addStretch(1) + + if link_count == 0: + self.social_link_gb.setVisible(False) + else: + self.social_link_gb.setVisible(True) + self.social_link_gb.layout().addStretch(1) + def add_wishlist_items(self, wishlist): wishlist = wishlist["data"]["Wishlist"]["wishlistItems"]["elements"] for game in wishlist: @@ -143,3 +179,11 @@ class ShopGameInfo(QWidget, Ui_shop_info): def button_clicked(self): webbrowser.open("https://www.epicgames.com/store/de/p/" + self.slug) + + +class SocialButton(QPushButton): + def __init__(self, icn, url): + super(SocialButton, self).__init__(icn, "") + self.url = url + self.clicked.connect(lambda: webbrowser.open(url)) + self.setToolTip(url) diff --git a/rare/components/tabs/shop/shop_models.py b/rare/components/tabs/shop/shop_models.py index d0272457..54d157f6 100644 --- a/rare/components/tabs/shop/shop_models.py +++ b/rare/components/tabs/shop/shop_models.py @@ -64,7 +64,10 @@ class ShopGame: api_data = product break if "pages" in api_data.keys(): - api_data = api_data["pages"][0] + for page in api_data["pages"]: + if page["_slug"] == "home": + api_data = page + break tmp = cls() tmp.title = search_data.get("title", "Fail") tmp.image_urls = ImageUrlModel.from_json(search_data["keyImages"]) diff --git a/rare/ui/components/tabs/store/shop_game_info.py b/rare/ui/components/tabs/store/shop_game_info.py index d66a7de5..589d8ed0 100644 --- a/rare/ui/components/tabs/store/shop_game_info.py +++ b/rare/ui/components/tabs/store/shop_game_info.py @@ -23,6 +23,11 @@ class Ui_shop_info(object): self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.image_stack = QtWidgets.QStackedWidget(shop_info) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.image_stack.sizePolicy().hasHeightForWidth()) + self.image_stack.setSizePolicy(sizePolicy) self.image_stack.setObjectName("image_stack") self.horizontalLayout.addWidget(self.image_stack) self.verticalLayout_2 = QtWidgets.QVBoxLayout() @@ -81,6 +86,11 @@ class Ui_shop_info(object): self.gridLayout_2 = QtWidgets.QGridLayout(self.req_group_box) self.gridLayout_2.setObjectName("gridLayout_2") self.verticalLayout.addWidget(self.req_group_box) + self.social_link_gb = QtWidgets.QGroupBox(shop_info) + self.social_link_gb.setObjectName("social_link_gb") + self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.social_link_gb) + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.verticalLayout.addWidget(self.social_link_gb) spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem2) @@ -101,6 +111,7 @@ class Ui_shop_info(object): self.open_store_button.setText(_translate("shop_info", "Buy Game in Epic Games Store")) self.wishlist_button.setText(_translate("shop_info", "Add to wishlist")) self.req_group_box.setTitle(_translate("shop_info", "Requirements")) + self.social_link_gb.setTitle(_translate("shop_info", "Social Links")) if __name__ == "__main__": diff --git a/rare/ui/components/tabs/store/shop_game_info.ui b/rare/ui/components/tabs/store/shop_game_info.ui index 09d92f42..3e49291d 100644 --- a/rare/ui/components/tabs/store/shop_game_info.ui +++ b/rare/ui/components/tabs/store/shop_game_info.ui @@ -25,27 +25,33 @@ - - -1 - + + + 0 + 0 + + + + -1 + - - - - 18 - - - - Error - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - + + + + 18 + + + + Error + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + @@ -62,23 +68,23 @@ - - - - You already own this game - - - - - - - TextLabel - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - + + + + You already own this game + + + + + + + TextLabel + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + @@ -149,22 +155,30 @@ - - - - Requirements - - - - - - - - Qt::Vertical - - - - 20 + + + + Requirements + + + + + + + + Social Links + + + + + + + + Qt::Vertical + + + + 20 40