Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Added new option to control grid size in grid view;
Browse files Browse the repository at this point in the history
Enabled most Gallery options in Visual section for OSX;
  • Loading branch information
twiddli committed Dec 26, 2015
1 parent 5a53158 commit a0e2106
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 80 deletions.
2 changes: 1 addition & 1 deletion version/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def init_toolbar(self):
# debug specfic code
if app_constants.DEBUG:
def debug_func():
os.environ.putenv("QT_DEVICE_PIXEL_RATIO", "2")
self.manga_list_view.get_visible_indexes()

debug_btn = QToolButton()
debug_btn.setText("DEBUG BUTTON")
Expand Down
9 changes: 5 additions & 4 deletions version/app_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
# sizes
MAIN_W = 1061 # main window
MAIN_H = 650 # main window
GRIDBOX_H_SIZE = 210
SIZE_FACTOR = get(10, 'Visual', 'size factor', int)
GRIDBOX_H_SIZE = 200 + SIZE_FACTOR
GRIDBOX_W_SIZE = GRIDBOX_H_SIZE//1.40 #1.47
GRIDBOX_LBL_H = 60
GRIDBOX_LBL_H = 50 + SIZE_FACTOR
GRIDBOX_H_SIZE += GRIDBOX_LBL_H
THUMB_H_SIZE = 200
THUMB_W_SIZE = 143
THUMB_H_SIZE = 190 + SIZE_FACTOR
THUMB_W_SIZE = 133 + SIZE_FACTOR

# Columns
COLUMNS = tuple(range(11))
Expand Down
127 changes: 55 additions & 72 deletions version/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ def paint(self, painter, option, index):
#area
{{
display:flex;
width:140px;
height:10px
width:{6}px;
height:{7}px
}}
#title {{
position:absolute;
Expand All @@ -668,7 +668,8 @@ def paint(self, painter, option, index):
</div>
</center>
</body>
""".format(title_size, artist_size, title, artist, title_color, artist_color))
""".format(title_size, artist_size, title, artist, title_color, artist_color,
130+app_constants.SIZE_FACTOR, 1+app_constants.SIZE_FACTOR))
text_area.setTextWidth(w)

#chapter_area = QTextDocument()
Expand All @@ -684,27 +685,41 @@ def center_img(width):
offset = diff//2
new_x += offset
return new_x

def img_too_big(start_x):
txt_layout = self.text_layout("Image is too big!", w, self.title_font, self.title_font_m)

clipping = QRectF(x, y+h//4, w, app_constants.GRIDBOX_LBL_H - 10)
txt_layout.draw(painter, QPointF(x, y+h//4),
clip=clipping)

# if we can't find a cached image
pix_cache = QPixmapCache.find(self.key(gallery.profile))
if isinstance(pix_cache, QPixmap):
self.image = pix_cache
img_x = center_img(self.image.width())
if self.image.height() < self.image.width(): #to keep aspect ratio
painter.drawPixmap(QPoint(img_x,y),
self.image)
if self.image.width() > w or self.image.height() > h:
img_too_big(img_x)
else:
painter.drawPixmap(QPoint(img_x,y),
self.image)
if self.image.height() < self.image.width(): #to keep aspect ratio
painter.drawPixmap(QPoint(img_x,y),
self.image)
else:
painter.drawPixmap(QPoint(img_x,y),
self.image)
else:
self.image = QPixmap(gallery.profile)
img_x = center_img(self.image.width())
QPixmapCache.insert(self.key(gallery.profile), self.image)
if self.image.height() < self.image.width(): #to keep aspect ratio
painter.drawPixmap(QPoint(img_x,y),
self.image)
if self.image.width() > w or self.image.height() > h:
img_too_big(img_x)
else:
painter.drawPixmap(QPoint(img_x,y),
self.image)
if self.image.height() < self.image.width(): #to keep aspect ratio
painter.drawPixmap(QPoint(img_x,y),
self.image)
else:
painter.drawPixmap(QPoint(img_x,y),
self.image)

# draw star if it's favorited
if gallery.fav == 1:
Expand Down Expand Up @@ -803,8 +818,9 @@ def draw_text_label(lbl_h):
p_path = QPainterPath()
p_path.setFillRule(Qt.WindingFill)
p_path.addRoundedRect(selected_rect, 5,5)
p_path.addRect(x,y, 20, 20)
p_path.addRect(x+w-20,y, 20, 20)
s_factor = app_constants.SIZE_FACTOR + 10
p_path.addRect(x,y, s_factor, s_factor)
p_path.addRect(x+w-s_factor,y, s_factor, s_factor)
painter.drawPath(p_path.simplified())
#painter.fillRect(selected_rect, QColor(164,164,164,120))
painter.restore()
Expand Down Expand Up @@ -865,7 +881,7 @@ def __init__(self, parent=None):
self.parent_widget = parent
self.setViewMode(self.IconMode)
self.H = app_constants.GRIDBOX_H_SIZE
self.W = app_constants.GRIDBOX_W_SIZE
self.W = app_constants.GRIDBOX_W_SIZE + (app_constants.SIZE_FACTOR//5)
self.setGridSize(QSize(self.W, self.H))
self.setResizeMode(self.Adjust)
self.setIconSize(QSize(app_constants.THUMB_W_SIZE,
Expand Down Expand Up @@ -913,63 +929,30 @@ def debug_print(a):

self.k_scroller = QScroller.scroller(self)

# unusable code
#def event(self, event):
# #if event.type() == QEvent.ToolTip:
# # help_event = QHelpEvent(event)
# # index = self.indexAt(help_event.globalPos())
# # if index is not -1:
# # QToolTip.showText(help_event.globalPos(), "Tooltip!")
# # else:
# # QToolTip().hideText()
# # event.ignore()
# # return True

# if event.type() == QEvent.Gesture:
# print("yes!")
# else:
# return super().event(event)

#def test_(self):
# "find all galleries in viewport"
# def col_next_prepare(index):
# "Calculates where the next index is"
# rect = self.visualRect(index)
# new_col = QPoint(rect.x() + rect.width() + rect.width(),
# rect.y())
# return new_col

# #find first index locatiion. A wild guess!!
# f_indx = self.indexAt(QPoint(87,130))
# found = 1
# f_rect = self.visualRect(f_indx) # need the first index's rect
# row = 1 # which row are we on
# while row: # while row is is valid
# rect = self.visualRect(f_indx) # rect of current index
# next_col_point = col_next_prepare(f_indx)
# #calculate the next row
# next_row_point = QPoint(f_rect.x()+10,
# rect.y()+rect.height()+(rect.height()//2))
# found += 1
# # while there are stil more colums
# while self.viewport().rect().contains(next_col_point,
# proper=True):
# next_indx = self.indexAt(next_col_point) # find the next index
# if not next_indx:
# break
# found += 1
# # time to prepare the next iteration
# next_col_point = col_next_prepare(next_indx)
# print('Moving to next col')
def get_visible_indexes(self, column=0):
"find all galleries in viewport"
gridW = self.W
gridH = self.H
region = self.viewport().visibleRegion()
idx_found = []

def idx_is_visible(idx):
idx_rect = self.visualRect(idx)
return region.contains(idx_rect) or region.intersects(idx_rect)

#get first index
first_idx = self.indexAt(QPoint(gridW//2, 0)) # to get indexes on the way out of view
if not first_idx.isValid():
first_idx = self.indexAt(QPoint(gridW//2, gridH//2))

if first_idx.isValid():
nxt_idx = first_idx
# now traverse items until index isn't visible
while(idx_is_visible(nxt_idx)):
idx_found.append(nxt_idx)
nxt_idx = nxt_idx.sibling(nxt_idx.row()+1, column)

# if self.viewport().rect().contains(next_row_point, proper=True):
# f_indx = self.indexAt(next_row_point)
# if f_indx.isValid():
# row += 1
# print('Moving to next row')
# row = None

# print('Found ', found)
return idx_found

def wheelEvent(self, event):
if self.gallery_window.isVisible():
Expand Down
2 changes: 1 addition & 1 deletion version/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def uncaught_exceptions(ex_type, ex, tb):
sys.excepthook = uncaught_exceptions

if app_constants.FORCE_HIGH_DPI_SUPPORT:
print("hi")
log_i("Enablind high DPI display support")
os.environ.putenv("QT_DEVICE_PIXEL_RATIO", "auto")

application = QApplication(sys.argv)
Expand Down
25 changes: 23 additions & 2 deletions version/settingsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
QLabel, QTabWidget, QLineEdit, QGroupBox, QFormLayout,
QCheckBox, QRadioButton, QSpinBox, QSizePolicy,
QScrollArea, QFontDialog, QMessageBox, QComboBox,
QFileDialog)
QFileDialog, QSlider)
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtGui import QPalette, QPixmapCache

Expand Down Expand Up @@ -212,6 +212,7 @@ def re_enforce(s):
self.search_on_enter.setChecked(True)
else:
self.search_every_keystroke.setChecked(True)
self.gallery_size.setValue(app_constants.SIZE_FACTOR//10)
# Visual / Grid View / Colors
self.grid_label_color.setText(app_constants.GRID_VIEW_LABEL_COLOR)
self.grid_title_color.setText(app_constants.GRID_VIEW_TITLE_COLOR)
Expand Down Expand Up @@ -376,6 +377,9 @@ def accept(self):
app_constants.GALLERY_FONT = (self.font_lbl.text(), self.font_size_lbl.value())
set(app_constants.GALLERY_FONT[0], 'Visual', 'gallery font family')
set(app_constants.GALLERY_FONT[1], 'Visual', 'gallery font size')
app_constants.SIZE_FACTOR = self.gallery_size.value() * 10
set(app_constants.SIZE_FACTOR, 'Visual', 'size factor')

# Visual / Grid View / Colors
if self.color_checker(self.grid_title_color.text()):
app_constants.GRID_VIEW_TITLE_COLOR = self.grid_title_color.text()
Expand Down Expand Up @@ -785,7 +789,8 @@ def make_login_forms(layout, cookies, baseHen_class):
self.gallery_type_ico = QCheckBox('File Type')
grid_gallery_display.addWidget(self.gallery_type_ico)
if sys.platform.startswith('darwin'):
grid_gallery_group.setEnabled(False)
self.external_viewer_ico.setEnabled(False)
self.gallery_type_ico.setEnabled(False)
gallery_text_mode = QWidget()
grid_gallery_main_l.addRow('Text Mode:', gallery_text_mode)
gallery_text_mode_l = QHBoxLayout()
Expand All @@ -808,6 +813,22 @@ def make_login_forms(layout, cookies, baseHen_class):
gallery_font.addWidget(self.font_size_lbl, 0, Qt.AlignLeft)
gallery_font.addWidget(choose_font, 0, Qt.AlignLeft)
gallery_font.addWidget(Spacer('h'), 1, Qt.AlignLeft)

gallery_size_lbl = QLabel(self)
self.gallery_size = QSlider(Qt.Horizontal, self)
self.gallery_size.valueChanged.connect(lambda x: gallery_size_lbl.setText(str(x+2)))
self.gallery_size.setMinimum(-2)
self.gallery_size.setMaximum(10)
self.gallery_size.setSingleStep(1)
self.gallery_size.setPageStep(3)
self.gallery_size.setTickInterval(1)
self.gallery_size.setTickPosition(QSlider.TicksBothSides)
self.gallery_size.setToolTip("Changes size of grid in gridview. Remember to re-generate thumbnails! DEFAULT=3")
gallery_size_l = QHBoxLayout()
gallery_size_l.addWidget(gallery_size_lbl)
gallery_size_l.addWidget(self.gallery_size)
grid_gallery_main_l.addRow("Gallery Size *", gallery_size_l)

# grid view / colors
grid_colors_group = QGroupBox('Colors', grid_view_general_page)
grid_view_layout.addWidget(grid_colors_group, 1, Qt.AlignTop)
Expand Down

0 comments on commit a0e2106

Please sign in to comment.