Skip to content

Commit

Permalink
Several updates to the QImageElement control and cell to make it more…
Browse files Browse the repository at this point in the history
… similar to QD
  • Loading branch information
escoz committed Jan 15, 2013
1 parent 9a7d692 commit bc1d224
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 119 deletions.
16 changes: 16 additions & 0 deletions QuickDialog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
D87B4FCE14F16197006DA833 /* QAutoEntryTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D87B4FC814F16197006DA833 /* QAutoEntryTableViewCell.m */; };
D8820B5116A246860070AE22 /* QCountdownElement.h in Headers */ = {isa = PBXBuildFile; fileRef = D8820B4F16A246860070AE22 /* QCountdownElement.h */; };
D8820B5216A246860070AE22 /* QCountdownElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D8820B5016A246860070AE22 /* QCountdownElement.m */; };
D8820C7D16A3543D0070AE22 /* QImageElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D8820C7716A352990070AE22 /* QImageElement.m */; };
D8820C7E16A3543F0070AE22 /* QImageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D8820C7916A352990070AE22 /* QImageTableViewCell.m */; };
D8820C7F16A3544C0070AE22 /* QImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = D8820C7616A352990070AE22 /* QImageElement.h */; };
D8820C8016A3544F0070AE22 /* QImageTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = D8820C7816A352990070AE22 /* QImageTableViewCell.h */; };
D894F38A15559D34000E3C0F /* NSMutableArray+IMSExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = D894F38815559D34000E3C0F /* NSMutableArray+IMSExtensions.h */; };
D894F38B15559D34000E3C0F /* NSMutableArray+IMSExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D894F38915559D34000E3C0F /* NSMutableArray+IMSExtensions.m */; };
D8A3DD87146045F000DE3528 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D8A3DD86146045F000DE3528 /* Localizable.strings */; };
Expand Down Expand Up @@ -308,6 +312,10 @@
D87B4FC814F16197006DA833 /* QAutoEntryTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QAutoEntryTableViewCell.m; path = quickdialog/QAutoEntryTableViewCell.m; sourceTree = SOURCE_ROOT; };
D8820B4F16A246860070AE22 /* QCountdownElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QCountdownElement.h; path = quickdialog/QCountdownElement.h; sourceTree = SOURCE_ROOT; };
D8820B5016A246860070AE22 /* QCountdownElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QCountdownElement.m; path = quickdialog/QCountdownElement.m; sourceTree = SOURCE_ROOT; };
D8820C7616A352990070AE22 /* QImageElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QImageElement.h; path = quickdialog/QImageElement.h; sourceTree = SOURCE_ROOT; };
D8820C7716A352990070AE22 /* QImageElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QImageElement.m; path = quickdialog/QImageElement.m; sourceTree = SOURCE_ROOT; };
D8820C7816A352990070AE22 /* QImageTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QImageTableViewCell.h; path = quickdialog/QImageTableViewCell.h; sourceTree = SOURCE_ROOT; };
D8820C7916A352990070AE22 /* QImageTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QImageTableViewCell.m; path = quickdialog/QImageTableViewCell.m; sourceTree = SOURCE_ROOT; };
D894F38815559D34000E3C0F /* NSMutableArray+IMSExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSMutableArray+IMSExtensions.h"; path = "quickdialog/NSMutableArray+IMSExtensions.h"; sourceTree = SOURCE_ROOT; };
D894F38915559D34000E3C0F /* NSMutableArray+IMSExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMutableArray+IMSExtensions.m"; path = "quickdialog/NSMutableArray+IMSExtensions.m"; sourceTree = SOURCE_ROOT; };
D8A3DD86146045F000DE3528 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = Localizable.strings; path = sample/Localizable.strings; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -509,6 +517,10 @@
D860356713E0534000CB1785 /* quickdialog */ = {
isa = PBXGroup;
children = (
D8820C7616A352990070AE22 /* QImageElement.h */,
D8820C7716A352990070AE22 /* QImageElement.m */,
D8820C7816A352990070AE22 /* QImageTableViewCell.h */,
D8820C7916A352990070AE22 /* QImageTableViewCell.m */,
D8820B4F16A246860070AE22 /* QCountdownElement.h */,
D8820B5016A246860070AE22 /* QCountdownElement.m */,
D87A4D8E169DB59500D4DD63 /* QAppearance.h */,
Expand Down Expand Up @@ -678,6 +690,8 @@
D81F2ED914BBAFCE0066C372 /* QBadgeLabel.h in Headers */,
D81F2EDA14BBAFCE0066C372 /* QDecimalTableViewCell.h in Headers */,
D81F2EDB14BBAFCE0066C372 /* QDecimalElement.h in Headers */,
D8820C7F16A3544C0070AE22 /* QImageElement.h in Headers */,
D8820C8016A3544F0070AE22 /* QImageTableViewCell.h in Headers */,
D81F2EDC14BBAFCE0066C372 /* QBadgeElement.h in Headers */,
D81F2EDD14BBAFCE0066C372 /* QBadgeTableCell.h in Headers */,
D81F2EDE14BBAFCE0066C372 /* QBooleanElement.h in Headers */,
Expand Down Expand Up @@ -900,6 +914,8 @@
D8E0748F165A7D08004E7035 /* QuickDialogController+Navigation.m in Sources */,
5C50E215ECB7C7D4B503AA4C /* QuickDialogController+Animations.m in Sources */,
D8820B5216A246860070AE22 /* QCountdownElement.m in Sources */,
D8820C7D16A3543D0070AE22 /* QImageElement.m in Sources */,
D8820C7E16A3543F0070AE22 /* QImageTableViewCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
32 changes: 16 additions & 16 deletions quickdialog/QDateEntryTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ - (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTable
}

- (NSString *) formatInterval: (NSTimeInterval) interval
{
unsigned long seconds = (unsigned long) interval;
unsigned long minutes = seconds / 60;
seconds %= 60;
unsigned long hours = minutes / 60;
minutes %= 60;

NSMutableString * result = [NSMutableString new];
if(hours)
[result appendFormat:@"%d hrs, ", (int) hours];

[result appendFormat:@"%d mins", (int) minutes];
//[result appendFormat:@"%d", (int) seconds];

return result;
}
{
unsigned long seconds = (unsigned long) interval;
unsigned long minutes = seconds / 60;
seconds %= 60;
unsigned long hours = minutes / 60;
minutes %= 60;

NSMutableString * result = [NSMutableString new];
if(hours)
[result appendFormat:@"%d hrs, ", (int) hours];

[result appendFormat:@"%d mins", (int) minutes];
//[result appendFormat:@"%d", (int) seconds];

return result;
}

@end
3 changes: 2 additions & 1 deletion quickdialog/QEntryTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@class QEntryElement;
@class QuickDialogTableView;
@class QTextField;
@class QImageElement;


@interface QEntryTableViewCell : QTableViewCell<UITextFieldDelegate> {
Expand Down Expand Up @@ -55,4 +56,4 @@

- (void)handleEditingChanged;

@end
@end
10 changes: 6 additions & 4 deletions quickdialog/QImageElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

@interface QImageElement : QEntryElement

@property (nonatomic, strong) UIImage *detailImageValue;
@property (nonatomic, strong) NSString *detailImageNamed;
@property (nonatomic, assign) CGFloat detailImageMaxLength;
@property (nonatomic, strong) UIImage *imageValue;
@property (nonatomic, strong) NSString *imageValueNamed;
@property (nonatomic, assign) float imageMaxLength;
@property(nonatomic) enum UIImagePickerControllerSourceType source;


- (QImageElement *)initWithTitle:(NSString *)title detailImage:(UIImage *)image;

@end
@end
161 changes: 90 additions & 71 deletions quickdialog/QImageElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,124 +12,143 @@
// permissions and limitations under the License.
//

#import "QImageElement.h"
#import "QImageTableViewCell.h"

@interface QImageElement () <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPopoverControllerDelegate>

@property (nonatomic, retain) UIImagePickerController *imagePickerController;
@property (nonatomic, strong) UIPopoverController *popoverController;
@property(nonatomic, retain) UIImagePickerController *imagePickerController;
@property(nonatomic, strong) UIPopoverController *popoverController;

@end

@implementation QImageElement
@implementation QImageElement {
enum UIImagePickerControllerSourceType _source;
}

@synthesize detailImageValue;
@synthesize detailImageMaxLength;
@synthesize imageValue;
@synthesize imageMaxLength;
@synthesize imagePickerController;
@synthesize popoverController;
@synthesize source = _source;

- (QImageElement *)initWithTitle:(NSString *)aTitle detailImage:(UIImage *)anImage {
self = [super init];
if (self) {
self.title = aTitle;
self.detailImageValue = anImage;
self.detailImageMaxLength = FLT_MAX;
}
return self;

- (QEntryElement *)init {
self = [super init];
if (self) {
_source = UIImagePickerControllerSourceTypePhotoLibrary;
self.imageMaxLength = FLT_MAX;
}

return self;
}

- (void)setDetailImageNamed:(NSString *)name {
self.detailImageValue = [UIImage imageNamed:name];
[self reducedImageIfNeeded];
- (QImageElement *)initWithTitle:(NSString *)aTitle detailImage:(UIImage *)anImage {
self = [super init];
if (self) {
self.title = aTitle;
self.imageValue = anImage;
self.imageMaxLength = FLT_MAX;
_source = UIImagePickerControllerSourceTypePhotoLibrary;
}
return self;
}

- (NSString *)detailImageNamed {
return nil;
- (void)setImageValueNamed:(NSString *)name {
self.imageValue = [UIImage imageNamed:name];
[self reducedImageIfNeeded];
}

- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
QImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformImageElement"];
if (cell==nil){
cell = [[QImageTableViewCell alloc] init];
}
[cell prepareForElement:self inTableView:tableView];
QImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformImageElement"];
if (cell == nil) {
cell = [[QImageTableViewCell alloc] init];
}
[cell prepareForElement:self inTableView:tableView];

return cell;
return cell;
}

- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)path {
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[tableView deselectRowAtIndexPath:path animated:YES];

self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

BOOL isPhone = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
if (isPhone) {
[controller displayViewController:self.imagePickerController];
} else {
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:path];
if ([tableViewCell isKindOfClass:[QImageTableViewCell class]]) {
UIView *presentingView = ((QImageTableViewCell *)tableViewCell).detailImageView;

UIPopoverController *aPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.imagePickerController];
[aPopoverController presentPopoverFromRect:presentingView.bounds
inView:presentingView
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
aPopoverController.delegate = self;
self.popoverController = aPopoverController;
}
}
[tableView deselectRowAtIndexPath:path animated:YES];

[self presentImagePicker:tableView controller:controller path:path];
}

- (void)presentImagePicker:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller path:(NSIndexPath *)path {
if ([UIImagePickerController isSourceTypeAvailable:_source]) {
self.imagePickerController.sourceType = _source;
} else {
NSLog(@"Source not available, using default Library type.");
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

BOOL isPhone = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
if (isPhone) {
[controller displayViewController:self.imagePickerController];
} else {
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:path];
if ([tableViewCell isKindOfClass:[QImageTableViewCell class]]) {
UIView *presentingView = ((QImageTableViewCell *) tableViewCell).imageViewButton;

UIPopoverController *aPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.imagePickerController];
[aPopoverController presentPopoverFromRect:presentingView.bounds
inView:presentingView
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
aPopoverController.delegate = self;
self.popoverController = aPopoverController;
}
}
}

- (UIImagePickerController *)imagePickerController {
if (!imagePickerController) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
}
return imagePickerController;
if (!imagePickerController) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
}
return imagePickerController;
}

- (void)dismissImagePickerController {
BOOL isPhone = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
if (isPhone) {
[self.imagePickerController dismissViewControllerAnimated:YES completion:NULL];
} else {
[self.popoverController dismissPopoverAnimated:YES];
}
BOOL isPhone = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
if (isPhone) {
[self.imagePickerController dismissViewControllerAnimated:YES completion:NULL];
} else {
[self.popoverController dismissPopoverAnimated:YES];
}
}

- (void)reducedImageIfNeeded {
if (self.detailImageValue.size.width > self.detailImageMaxLength || self.detailImageValue.size.height > self.detailImageMaxLength) {
float scale = self.detailImageMaxLength / MAX(self.detailImageValue.size.width, self.detailImageValue.size.height);
CGSize scaledSize = CGSizeMake(self.detailImageValue.size.width*scale, self.detailImageValue.size.height*scale);

UIGraphicsBeginImageContext(scaledSize);
[self.detailImageValue drawInRect:CGRectMake(0, 0, scaledSize.width, scaledSize.height)];
self.detailImageValue = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
if (self.imageValue.size.width > self.imageMaxLength || self.imageValue.size.height > self.imageMaxLength) {
float scale = self.imageMaxLength / MAX(self.imageValue.size.width, self.imageValue.size.height);
CGSize scaledSize = CGSizeMake(self.imageValue.size.width * scale, self.imageValue.size.height * scale);

UIGraphicsBeginImageContext(scaledSize);
[self.imageValue drawInRect:CGRectMake(0, 0, scaledSize.width, scaledSize.height)];
self.imageValue = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}

#pragma mark -
#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

self.detailImageValue = [info valueForKey:UIImagePickerControllerOriginalImage];
[self reducedImageIfNeeded];
self.imageValue = [info valueForKey:UIImagePickerControllerOriginalImage];
[self reducedImageIfNeeded];

[self dismissImagePickerController];
[self dismissImagePickerController];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissImagePickerController];
[self dismissImagePickerController];
}

#pragma mark -
#pragma mark UIPopoverControllerDelegate

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.popoverController = nil;
self.popoverController = nil;
}

@end
6 changes: 3 additions & 3 deletions quickdialog/QImageTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
@interface QImageTableViewCell : QEntryTableViewCell {

QImageElement *_imageElement;
UIImageView *_detailImageView;
UIButton *_imageViewButton;
}

@property (nonatomic, retain) UIImageView *detailImageView;
@property (nonatomic, retain) UIButton *imageViewButton;

- (void)prepareForElement:(QImageElement *)element inTableView:(QuickDialogTableView *)tableView;
- (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTableView *)tableView;
- (void)createSubviews;

@end
Loading

0 comments on commit bc1d224

Please sign in to comment.